* What went wrong: Execution failed for task ':app:transformClassesWithMultidexlistForRelease'. > java.lang.UnsupportedOperationException (no error message)
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
难道是开了混淆,导致一些类找不到?但是类找不到只是运行时的异常而已,应该只会在运行APP的时候抛出“ClassNotFoundException”,不应该导致构建失败啊。难道是APT生成的类格式不对,导致Javac在编译该类的时候失败?于是我打开由APT工具生成的AutoGeneratedRouteTable.java类文件瞧瞧,发文件类的格式很完美,没有问题,甚至由于担心是中文引起的问题,我还把“念两句诗”改成“Sing two poems”,问题依旧。
publicenum RetentionPolicy { /** * Annotations are to be discarded by the compiler. */ SOURCE,
/** * Annotations are to be recorded in the class file by the compiler * but need not be retained by the VM at run time. This is the default * behavior. */ CLASS,
/** * Annotations are to be recorded in the class file by the compiler and * retained by the VM at run time, so they may be read reflectively. * * @see java.lang.reflect.AnnotatedElement */ RUNTIME }
以下放出这次定位问题的大致过程。 ① 先定位 transformClassesWithMultidexlistForRelease 任务的源码。通过任务名字,可以很快地定位到 MultiDexTransform.java 这个类里面来,以下是这个类在执行任务时候做的工作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
@Override publicvoidtransform(@NonNull TransformInvocation invocation) throws IOException, TransformException, InterruptedException { // Re-direct the output to appropriate log levels, just like the official ProGuard task. LoggingManager loggingManager = invocation.getContext().getLogging(); loggingManager.captureStandardOutput(LogLevel.INFO); loggingManager.captureStandardError(LogLevel.WARN);
② 定位到dx.jar工具里具体出问题的地方,通过上面的分析以及构建失败输出的LOG,可以看到Gradle插件调用了dx.jar并传入了build/intermediates/multi-dex/release/componentClasses.jar和build/intermediates/transforms/proguard/release/jars/3/1f/main.jar两个文件。直接调用该命令试试。
Exception in thread "main" com.android.dx.cf.iface.ParseException: name already added: string{"a"} at com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:156) at com.android.dx.cf.direct.AttributeListParser.parseIfNecessary(AttributeListParser.java:115) at com.android.dx.cf.direct.AttributeListParser.getList(AttributeListParser.java:106) at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:558) at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406) at com.android.dx.cf.direct.DirectClassFile.parseToEndIfNecessary(DirectClassFile.java:397) at com.android.dx.cf.direct.DirectClassFile.getAttributes(DirectClassFile.java:311) at com.android.multidex.MainDexListBuilder.hasRuntimeVisibleAnnotation(MainDexListBuilder.java:191) at com.android.multidex.MainDexListBuilder.keepAnnotated(MainDexListBuilder.java:167) at com.android.multidex.MainDexListBuilder.<init>(MainDexListBuilder.java:121) at com.android.multidex.MainDexListBuilder.main(MainDexListBuilder.java:91) at com.android.multidex.ClassReferenceListBuilder.main(ClassReferenceListBuilder.java:58) Caused by: java.lang.IllegalArgumentException: name already added: string{"a"} at com.android.dx.rop.annotation.Annotation.add(Annotation.java:208) at com.android.dx.cf.direct.AnnotationParser.parseAnnotation(AnnotationParser.java:264) at com.android.dx.cf.direct.AnnotationParser.parseAnnotations(AnnotationParser.java:223) at com.android.dx.cf.direct.AnnotationParser.parseAnnotationAttribute(AnnotationParser.java:152) at com.android.dx.cf.direct.StdAttributeFactory.runtimeInvisibleAnnotations(StdAttributeFactory.java:616) at com.android.dx.cf.direct.StdAttributeFactory.parse0(StdAttributeFactory.java:93) at com.android.dx.cf.direct.AttributeFactory.parse(AttributeFactory.java:96) at com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:142) ... 11 more
③ 最后定位到源码里具体出问题的地方,查看dx工具里的com.android.dx.rop.annotation.Annotation.java的源码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
privatefinal TreeMap<CstString, NameValuePair> elements; /** * Add an element to the set of (name, value) pairs for this instance. * It is an error to call this method if there is a preexisting element * with the same name. * * @param pair {@code non-null;} the (name, value) pair to add to this instance */publicvoidadd(NameValuePair pair){ throwIfImmutable(); if (pair == null) { thrownew NullPointerException("pair == null"); } CstString name = pair.getName(); if (elements.get(name) != null) { thrownew IllegalArgumentException("name already added: " + name); } elements.put(name, pair); }
Caused by: com.android.ide.common.process.ProcessException: Error while executing java process with main classcom.android.multidex.ClassReferenceListBuilderwitharguments{build/intermediates/multi-dex/release/componentClasses.jar build/intermediates/transforms/proguard/release/jars/3/1f/main.jar} at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:74) at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:49) at com.android.builder.core.AndroidBuilder.createMainDexList(AndroidBuilder.java:1384) at com.android.build.gradle.internal.transforms.MultiDexTransform.callDx(MultiDexTransform.java:309) at com.android.build.gradle.internal.transforms.MultiDexTransform.computeList(MultiDexTransform.java:265) at com.android.build.gradle.internal.transforms.MultiDexTransform.transform(MultiDexTransform.java:186)