3

I'm migrating my existing multi-dex app into an Instant app and converted my app into the recommended project structure.

There were a bunch of compilation issues related which were successfully resolved however while trying to run the install-able "application" module, I'm running into the following error as stated below in the stack trace.

I'm suspecting this is because my now baseFeature module (prior multi-dex app) is not compatible with the instant app architecture.

Any cues on what's the best way to handle this? If anyone can point to how would an existing multidex app port to the new instant app architecture, it would be great :)

Stack Trace:

Error converting bytecode to dex:
Cause: InvokeDynamic not supported
com.android.dx.cf.iface.ParseException: InvokeDynamic not supported
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
    at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
    at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:720)
    at com.android.ide.common.internal.WaitableExecutor.waitForTasksWithQuickFail(WaitableExecutor.java:146)
    at com.android.builder.dexing.DexArchiveBuilder.processOutputs(DexArchiveBuilder.java:110)
    at com.android.builder.dexing.DexArchiveBuilder.convert(DexArchiveBuilder.java:91)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.lambda$cacheMissAction$0(DexArchiveBuilderTransformCallable.java:236)
    at com.android.builder.utils.FileCache.lambda$createFile$1(FileCache.java:260)
    at com.android.builder.utils.FileCache.lambda$null$5(FileCache.java:443)
    at com.android.builder.utils.SynchronizedFile.doActionWithSingleProcessLocking(SynchronizedFile.java:291)
    at com.android.builder.utils.SynchronizedFile.write(SynchronizedFile.java:234)
    at com.android.builder.utils.FileCache.lambda$queryCacheEntry$6(FileCache.java:415)
    at com.android.builder.utils.SynchronizedFile.doActionWithSingleProcessLocking(SynchronizedFile.java:291)
    at com.android.builder.utils.SynchronizedFile.read(SynchronizedFile.java:217)
    at com.android.builder.utils.FileCache.queryCacheEntry(FileCache.java:391)
    at com.android.builder.utils.FileCache.createFile(FileCache.java:273)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.getFromCacheAndCreateIfMissing(DexArchiveBuilderTransformCallable.java:185)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.call(DexArchiveBuilderTransformCallable.java:147)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.call(DexArchiveBuilderTransformCallable.java:53)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.android.dx.cf.iface.ParseException: InvokeDynamic not supported
    at com.android.dx.cf.cst.ConstantPoolParser.determineOffsets(ConstantPoolParser.java:226)
    at com.android.dx.cf.cst.ConstantPoolParser.parse(ConstantPoolParser.java:132)
    at com.android.dx.cf.cst.ConstantPoolParser.parseIfNecessary(ConstantPoolParser.java:124)
    at com.android.dx.cf.cst.ConstantPoolParser.getPool(ConstantPoolParser.java:115)
    at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:491)
    at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
    at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
    at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
    at com.android.builder.dexing.DexArchiveBuilderCallable.parseClass(DexArchiveBuilderCallable.java:86)
    at com.android.builder.dexing.DexArchiveBuilderCallable.call(DexArchiveBuilderCallable.java:70)
    at com.android.builder.dexing.DexArchiveBuilderCallable.call(DexArchiveBuilderCallable.java:43)
    ... 5 more
...while preparsing cst 0032 at offset 000000f1
...while parsing RangeDialogFragment.class

Execution failed for task ':installapp:transformClassesWithDexBuilderForDebug'.
    com.android.build.api.transform.TransformException:  java.lang.RuntimeException: java.lang.RuntimeException:  java.util.concurrent.ExecutionException:  java.util.concurrent.ExecutionException:  com.android.builder.utils.FileCache$FileCreatorException:  
    com.android.builder.dexing.DexArchiveBuilder$DexBuilderException: Unable to convert input to dex archive.
Volo
  • 28,673
  • 12
  • 97
  • 125
prerak
  • 399
  • 4
  • 8
  • This looks more like a java 8 dependency or retrolambda issue than a multi-dex one. See [related question](https://stackoverflow.com/questions/40080002/invokedynamic-not-supported-when-building-for-android). – pbaumann May 31 '17 at 03:39
  • Not sure, I do use java8 methods but don't have retrolambda. I guess one of the dependencies might be using it? – prerak Jun 03 '17 at 19:14

1 Answers1

2

Feature modules does not support multidex at the moment, so each feature module should use a single dex.

There is no generic solution to this issue, but I can give a few suggestions.

  1. Try to move your UI code from your base feature module to another feature module. Android support libraries have the biggest impact on method count so moving support libraries from your base-feature to ui-feature module should help.
  2. Play Services is the other major library that impact the method count. If you can, do not add the whole play services sdk but instead use subsets of it.
  3. Use Apk Analyzer or DexCount to pinpoint libraries that use the highest amount of methods and try to move them to separate feature modules.
  4. Proguard. Minification should be able to remove unused methods and help you fit the base module in a single dex. However, Proguard is quite problematic with instantapps at the moment. You will need to create extra proguard rules for each module.