Compiling basic Android app without Gradle – d8 errors

  Kiến thức lập trình

I wish to port a small utility I prototyped on Windows as a simple app. I use a 10-year old computer, so from what I gather tools like Gradle and Android Studio would run too slow for me to be able to meaningfully iterate fast (and the windows toolchain and build I . I also know nothing about Android app structure, so seeing the different stages of compilation is instructive anyway.

I’ll list the stages I’ve been through and then my current error, as I’ve no idea if my setup or some earlier stage might be causing the issue. I am getting errors trying to compile an example app.

I am following this tutorial : https://hereket.com/posts/android_from_command_line/
(I installed build/platform tools and an image for v28.0.3 and have JDK 22).

The differences I’ve had are :
1- aapt wouldn’t run if the gen folder wasn’t explicitely created beforehand
2- d8 refused a *.class parameter, so I’ve generated the file list manually.

I worked around the issue mentioned here : Error while running dx or d8 tool for Android in the same fashion.

d8 currently gives me the following error :

java.lang.IllegalArgumentException
        at com.android.tools.r8.org.objectweb.asm.ClassReader.<init>(ClassReader.java:160)
        at com.android.tools.r8.org.objectweb.asm.ClassReader.<init>(ClassReader.java:143)
        at com.android.tools.r8.org.objectweb.asm.ClassReader.<init>(ClassReader.java:418)
        at com.android.tools.r8.graph.JarClassFileReader.read(JarClassFileReader.java:66)
        at com.android.tools.r8.dex.ApplicationReader$ClassReader.lambda$readClassSources$1(ApplicationReader.java:231)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedInterruptibleCallable.compute(ForkJoinTask.java:1689)
        at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1641)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)

Input command is this :

d8 --debug --output __buildapkmy_classes.jar --no-desugaring  __buildobj
comuserandroid_build_testMainActivity.class objcomuserandroid_
build_testR$attr.class __buildobjcomuserandroid_build_testR$id.class __buildobjcomuserandroid_build_testR$layout.class __buildobjcomuser
android_build_testR$style.class __buildobjcomuserandroid_build_testR.cl
ass

The only difference being I give it an absolute path.
If I instead remove all files except one with path removed, I obtain :

Error in R.class:
  Error with input file: R.class
Compilation failed
(etc. - same call stack)

Any idea what causes this ? If so, any idea how I could have worked it out without what seems to be a considerable amount of implicit knowledge ?

LEAVE A COMMENT