Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 18, 2019
1 parent ba015f7 commit 9d9b70f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install JDK and build project
run: |
. ./.github/scripts/install-jdk.sh --feature ea --os linux-x64
./mvnw verify -Pjava15
./mvnw verify -Pjava15 -Pjava15-compatibility
hotspot-supported:
name: HotSpot (supported)
strategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,22 @@ class ForSdkCompiler implements DexProcessor {
static {
Dispatcher dispatcher;
try {
dispatcher = Dispatcher.ForApi26LevelCompatibleVm.make();
Class<?> dxContextType = Class.forName("com.android.dx.command.dexer.DxContext");
dispatcher = new Dispatcher.ForApi26LevelCompatibleVm(CfTranslator.class.getMethod("translate",
dxContextType,
DirectClassFile.class,
byte[].class,
CfOptions.class,
DexOptions.class,
DexFile.class), dxContextType.getConstructor());
} catch (Throwable ignored) {
try {
dispatcher = Dispatcher.ForLegacyVm.make();
dispatcher = new Dispatcher.ForLegacyVm(CfTranslator.class.getMethod("translate",
DirectClassFile.class,
byte[].class,
CfOptions.class,
DexOptions.class,
DexFile.class), DexOptions.class.getField("targetApiLevel"));
} catch (Throwable throwable) {
dispatcher = new Dispatcher.Unavailable(throwable.getMessage());
}
Expand Down Expand Up @@ -408,34 +420,22 @@ class ForLegacyVm implements Dispatcher {
*/
private final Method translate;

/**
* The {@code DexOptions#targetApiLevel} field.
*/
private final Field targetApi;

/**
* Creates a new dispatcher.
*
* @param translate The {@code CfTranslator#translate(DirectClassFile, byte[], CfOptions, DexOptions, DexFile)} method.
* @param targetApi
* @param targetApi The {@code DexOptions#targetApiLevel} field.
*/
protected ForLegacyVm(Method translate, Field targetApi) {
this.translate = translate;
this.targetApi = targetApi;
}

/**
* Creates a new dispatcher.
*
* @return The created dispatcher.
* @throws Exception If the dispatcher cannot be created.
*/
protected static Dispatcher make() throws Exception {
return new ForLegacyVm(CfTranslator.class.getMethod("translate",
DirectClassFile.class,
byte[].class,
CfOptions.class,
DexOptions.class,
DexFile.class), DexOptions.class.getField("targetApiLevel"));
}

/**
* {@inheritDoc}
*/
Expand All @@ -458,11 +458,14 @@ public ClassDefItem translate(DirectClassFile directClassFile,
}
}

/**
* {@inheritDoc}
*/
public void setTargetApi(DexOptions dexOptions, int targetApiLevel) {
try {
targetApi.set(dexOptions, targetApiLevel);
} catch (IllegalAccessException exception) {
throw new IllegalStateException();
throw new IllegalStateException("Cannot access an Android dex file translation method", exception);
}
}
}
Expand Down Expand Up @@ -493,23 +496,6 @@ protected ForApi26LevelCompatibleVm(Method translate, Constructor<?> dxContext)
this.dxContext = dxContext;
}

/**
* Creates a new dispatcher.
*
* @return The created dispatcher.
* @throws Exception If the dispatcher cannot be created.
*/
protected static Dispatcher make() throws Exception {
Class<?> dxContextType = Class.forName("com.android.dx.command.dexer.DxContext");
return new ForApi26LevelCompatibleVm(CfTranslator.class.getMethod("translate",
dxContextType,
DirectClassFile.class,
byte[].class,
CfOptions.class,
DexOptions.class,
DexFile.class), dxContextType.getConstructor());
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public static ClassFileVersion ofJavaVersion(int javaVersion) {
case 14:
return JAVA_V14;
case 15:
return JAVA_V14;
return JAVA_V15;
default:
if (OpenedClassReader.EXPERIMENTAL && javaVersion > 0) {
return new ClassFileVersion(BASE_VERSION + javaVersion);
Expand Down

0 comments on commit 9d9b70f

Please sign in to comment.