解决AndroidStudio添加ProjectLibary后在编译时遇到的各种问题之解决方式索引(finished with non-zero exit value and so on...)

时间:2022-09-13 00:17:37
解决AndroidStudio添加ProjectLibary后在编译时遇到的各种问题之解决方式索引(finished with non-zero exit value and so on...)

因为项目需要,我需要将一个外部工程作为Libary导入项目,起初导入还是比较简单的,但是在编译的时候就遇到了各种问题:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 3

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/view/CollapsibleActionView.class

Error:Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> com/baidu/mapapi/search/sug/OnGetSuggestionResultListener

现在将这些问题汇总,做一个解决方案的索引,以供大家在以后再遇到相同的问题,好有办法解决。

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2
这个问题主要的原因就是引入的Libary与现有的工程中的某些Libs重复了,请详细检查并确保所有使用的lib只有一份,比如v4,v7,Gson...,该问题的具体答案请参见: http://*.com/questions/32889059/android-studio-1-4-and-vector-image/32889565#32889565,另,使用android的官方支持库请参见: http://developer.android.com/tools/support-library/features.html

上面这个问题解决完成之后很有可能再会有别的问题冒出来:

Finished with Non Zero Exit Value 3:
具体解决方式请参见: https://*.com/questions/29720831/finished-with-non-zero-exit-value-3/30930734#30930734?newreg=12a5055f9ee3430f9591837a30307c1f,另需注意compile 与provided 的区别,在所有问题解决完毕之后,如果遇到在Application中初始化第三方含有.so的SDK的话,可能会引起Class not found异常,请删除App,然后将运行程序中的build.gradle文件中的provided更改为compile,然后clean,重新编译运行。

Gradle DSL method not found: 'testCompile()'
http://*.com/questions/25252637/gradle-build-script-error-occurs-when-i-attempt-to-use-testcompile-in-dependan

Android Studio 2.0 Preview: ':app:transformClassesWithInstantRunForDebug' FAILED
http://*.com/questions/34059352/android-studio-2-0-preview-apptransformclasseswithinstantrunfordebug-failed

Error:Execution failed for task ':app:clean'.
> Unable to delete file: F:\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.0\jars\classes.jar
请在重启AS的时候删除这个文件即可

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/view/CollapsibleActionView.class
这个问题是因为在工程中既有本地的lib.jar文件,又有compile链接,请确认全部统一即可。



还有问题请Google.
另推荐一个适合在编程时听音乐的网站:http://musicforprogramming.net/