Skip to content

Commit

Permalink
* actool: support for AltIcons and other options (MobiVM#718)
Browse files Browse the repository at this point in the history
# the issue
- originally was reported in MobiVM#636 (support for alt icons)
- also if xcassets contain multiple icons -- random one was picked for the app
- also if xcassets contain multiple launch images -- random one was picked for the app
# the fix
`robovm.xml` was extended with `actool` options:
```
<config>
    <tools>
        <actool>
            <appIcon>AppIcon</appIcon>
            <includeAllAppIcons>true</includeAllAppIcons>
        </actool>
    </tools>
</config>
```

new parameters:
- `appicon` - specifies which icon to use for app (in case of multiple)
- `launchImage` -- specifies which launchImage to use (in case of multiple)
- `includeAllAppIcons` -- will add `--include-all-app-icons` command line argument to include all app icons
- `args` -- allows to add raw arguments for actool
  • Loading branch information
dkimitsa authored Apr 12, 2023
1 parent 83c6d99 commit de7f907
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.robovm.compiler.config.tools;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Settings to provide custom actool arguments
* @author dkimitsa
*/
public class ActoolOptions {
@ElementList(required = false, entry = "arg")
private ArrayList<String> args;

@Element(required = false)
private String appIcon;

@Element(required = false)
private String launchImage;

@Element(required = false)
private Boolean includeAllAppIcons;

public List<String> getArguments() {
return args != null ? Collections.unmodifiableList(args) : Collections.emptyList();
}

public String getAppIconName() {
return appIcon;
}

public String getLaunchImageName() {
return launchImage;
}

public boolean shouldIncludeAllAppIcons() {
return includeAllAppIcons != null ? includeAllAppIcons : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ public class Tools {

@Element(required = false)
private LinkerOptions linker;


@Element(required = false)
private ActoolOptions actool;

public TextureAtlas getTextureAtlas() {
return textureAtlas;
}

public LinkerOptions getLinker() {
return linker;
}

public ActoolOptions getActool() {
return actool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.robovm.compiler.config.Config;
import org.robovm.compiler.config.CpuArch;
import org.robovm.compiler.config.OS;
import org.robovm.compiler.config.tools.ActoolOptions;
import org.robovm.compiler.config.tools.TextureAtlas;
import org.robovm.compiler.log.ConsoleLogger;
import org.robovm.compiler.log.Logger;
Expand Down Expand Up @@ -239,37 +239,80 @@ public static void actool(Config config, File partialInfoPlist, File outDir, Fil

public static void actool(Config config, File partialInfoPlist, File outDir, List<File> inDirs) throws IOException {
List<Object> opts = new ArrayList<>();

String appIconSetName = null;
boolean appIconSetNameByArgs = false;
String launchImagesName = null;

final String appiconset = "appiconset";
final String launchimage = "launchimage";

for (File inDir : inDirs) {
for (String fileName : inDir.list()) {
String ext = FilenameUtils.getExtension(fileName);
if (ext.equals(appiconset)) {
appIconSetName = FilenameUtils.getBaseName(fileName);
} else if (ext.equals(launchimage)) {
launchImagesName = FilenameUtils.getBaseName(fileName);
boolean launchImagesNameByArgs = false;
boolean includeAllAppIcons = false;

// pick values from config of robovm.xml
if (config.getTools() != null && config.getTools().getActool() != null) {
ActoolOptions options = config.getTools().getActool();
opts.addAll(options.getArguments());
// if "--app-icon" specified in arguments will not use iconName option or look up for asset
appIconSetNameByArgs = opts.contains("--app-icon");
// if "--launch-image" specified in arguments will not use launchImagesName option or look up for asset
launchImagesNameByArgs = opts.contains("--launch-image");
// pick other options
includeAllAppIcons = options.shouldIncludeAllAppIcons();
appIconSetName = appIconSetNameByArgs ? null : options.getAppIconName();
launchImagesName = launchImagesNameByArgs ? null: options.getLaunchImageName();
}

// look for icon and launch image sets if not specified by config
// these options might be provided also in argument list. do lookup only if required
List<String> availableIcons = appIconSetName == null && !appIconSetNameByArgs ? new ArrayList<>() : null;
List<String> availableImages = launchImagesName == null && !launchImagesNameByArgs ? new ArrayList<>() : null;
if (availableIcons != null || availableImages != null) {
final String appiconset = "appiconset";
final String launchimage = "launchimage";

for (File inDir : inDirs) {
for (String fileName : inDir.list()) {
String ext = FilenameUtils.getExtension(fileName);
if (ext.equals(appiconset)) {
if (availableIcons != null)
availableIcons.add(FilenameUtils.getBaseName(fileName));
} else if (ext.equals(launchimage)) {
if (availableImages != null)
availableImages.add(FilenameUtils.getBaseName(fileName));
}
}
}
}
if (appIconSetName != null || launchImagesName != null) {
if (appIconSetName != null) {
opts.add("--app-icon");
opts.add(appIconSetName);

// pick values
if (availableIcons != null && availableIcons.size() >= 1) {
appIconSetName = availableIcons.get(0);
if (availableIcons.size() > 1)
config.getLogger().error("actool: multiple .appiconset found but %s will be used", appIconSetName);
}
if (launchImagesName != null) {
opts.add("--launch-image");
opts.add(launchImagesName);
if (availableImages != null && availableImages.size() >= 1) {
launchImagesName = availableImages.get(0);
if (availableImages.size() > 1)
config.getLogger().error("actool: multiple .launchimage found but %s will be used", launchImagesName);
}
}

if (appIconSetName != null) {
opts.add("--app-icon");
opts.add(appIconSetName);
appIconSetNameByArgs = true;
}
if (launchImagesName != null) {
opts.add("--launch-image");
opts.add(launchImagesName);
launchImagesNameByArgs = true;
}

if (appIconSetNameByArgs || launchImagesNameByArgs) {
opts.add("--output-partial-info-plist");
opts.add(partialInfoPlist);
}

if (includeAllAppIcons) {
opts.add("--include-all-app-icons");
}

opts.add("--platform");
if (IOSTarget.isDeviceArch(config.getArch())) {
opts.add("iphoneos");
Expand Down

0 comments on commit de7f907

Please sign in to comment.