-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
d8 desugaring of Java 8 / Java 11 features seems to work without any --library arguments despite d8's warnings. The resulting smali code no longer contains 'invoke-custom' statements. Example: String#isBlank (Java 11) is replaced by a $$ExternalSyntheticBackport class.
- Loading branch information
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/org/ollide/java2smali/D8Class2DexHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.ollide.java2smali | ||
|
||
import com.android.tools.r8.D8 | ||
import com.android.tools.r8.D8Command | ||
import com.android.tools.r8.OutputMode | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.util.containers.stream | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
import java.util.stream.Collectors | ||
|
||
object D8Class2DexHelper { | ||
|
||
/** | ||
* Uses the D8 tool from the Android Build Tools to create | ||
* a .dex version of a compiled java file (.class) | ||
* | ||
* @param inputClassFilePaths full paths to the compiled .class file | ||
* @param outputDexPath this will be the dex output file's path and name | ||
* @return `true` if dx ran successfully, otherwise `false` | ||
*/ | ||
fun dexClassFile(inputClassFilePaths: Array<String>, outputDexPath: Path): Boolean { | ||
val classFiles = inputClassFilePaths.stream().map { Paths.get(it) }.collect(Collectors.toList()) | ||
|
||
val command = D8Command.builder() | ||
.setIntermediate(true) | ||
.setMinApiLevel(30) | ||
.addProgramFiles(classFiles) | ||
// Add --library android.jar ? | ||
// .addLibraryFiles(Paths.get("")) | ||
.setOutput(outputDexPath, OutputMode.DexIndexed) | ||
.build() | ||
|
||
return try { | ||
D8.run(command) | ||
true | ||
} catch (e: Exception) { | ||
LOG.error("Error running D8", e) | ||
false | ||
} | ||
} | ||
|
||
private val LOG = Logger.getInstance(D8Class2DexHelper::class.java) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters