最近使用androidstudio 老是出问题,都有点返回继续用eclipse 的冲动了,问题是 :当我用真机5.1.1手机上运行时 没事,在4.4.4手机上却无法编译成功,出现以下问题


Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72310Library
:app:prepareComAndroidSupportSupportV42310Library
:app:prepareYunDuoVRModelCommonUnspecifiedLibrary
:app:prepareYunDuoVRModelCommonwidgetUnspecifiedLibrary
:app:prepareYunDuoVRModelPanowidgetUnspecifiedLibrary
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
E:\YunDuoVR\app\src\main\AndroidManifest.xml:16:5-81 Warning:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:16:5-81 duplicated with element declared at AndroidManifest.xml:7:5-81
E:\YunDuoVR\app\src\main\AndroidManifest.xml:17:5-80 Warning:
Element uses-permission#android.permission.READ_EXTERNAL_STORAGE at AndroidManifest.xml:17:5-80 duplicated with element declared at AndroidManifest.xml:9:5-80
E:\YunDuoVR\app\src\main\AndroidManifest.xml:30:5-67 Warning:
Element uses-permission#android.permission.INTERNET at AndroidManifest.xml:30:5-67 duplicated with element declared at AndroidManifest.xml:18:5-67
E:\YunDuoVR\app\src\main\AndroidManifest.xml:40:5-84 Warning:
Element uses-permission#android.permission.MOUNT_UNMOUNT_FILESYSTEMS at AndroidManifest.xml:40:5-84 duplicated with element declared at AndroidManifest.xml:8:5-84
E:\YunDuoVR\app\src\main\AndroidManifest.xml:43:5-81 Warning:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:43:5-81 duplicated with element declared at AndroidManifest.xml:16:5-81
:app:processDebugResources
:app:generateDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:mergeDebugAndroidTestShaders
:app:compileDebugAndroidTestShaders
:app:generateDebugAndroidTestAssets
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:compileDebugJavaWithJavac
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:buildInfoDebugLoader
:app:transformClassesWithExtractJarsForDebug
:app:transformClassesWithInstantRunVerifierForDebug
:app:transformClassesWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders
:app:transformNative_libsWithMergeJniLibsForDebug
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug
:app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:transformClassesWithInstantRunForDebug
:app:transformClasses_enhancedWithInstant+reloadDexForDebug UP-TO-DATE
:app:incrementalDebugTasks
:app:prePackageMarkerForDebug
:app:fastDeployDebugExtractor
:app:generateDebugInstantRunAppInfo
:app:transformClassesWithDexForDebug
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.tencent.mm.sdk.b.b) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.commons.httpclient.HttpMethodBase$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_11\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 55.02 secs
Information:26 errors
Information:0 warnings
Information:See complete output in console


后来查阅了很多资料,可能是随着项目不断的壮大,导入的jar越来越多,可能是jar包冲突,后来我看了一篇文章,

http://blog.csdn.net/yanzi1225627/article/details/47361375

出现这个问题是因为最新的v4包(compile ‘com.Android.support:support-v4:22.2.1’)已经包含了annotation.jar这个包,但其他jar包里也包含这个包造成的。而非同时包含了v4/V7造成的,于是在v7包里进行如下设置:

<code class="hljs cs has-numbering"><span style="font-size:18px;">compile (<span class="hljs-string">'com.android.support:appcompat-v7:22.2.1'</span>){        exclude <span class="hljs-keyword">group</span>: <span class="hljs-string">"com.android.support"</span>, module: <span class="hljs-string">"support-v4"</span>    }</span></code>

即设置v7包不包含v4,这个设了也是没用的。只要确保用v4和v7 的地方版本一致即可。正确的解决方法有如下几种:
1,找到项目其他的依赖包,一定在libs里的某个jar包里,隐藏着annotation.jar包,将其删掉就ok了,此为最正统的解决方法;
2,降级v4包,因为高版本的v4才包含annotation.jar,可以在最外面的build.grable里强制设置:

<code class="hljs matlab has-numbering"><span style="font-size:18px;">allprojects <span class="hljs-cell">{    repositories {        jcenter()    }</span>    <span class="hljs-transposed_variable">configurations.</span>all <span class="hljs-cell">{        resolutionStrategy.force <span class="hljs-string">'com.android.support:support-annotations:22.1.0'</span>    }</span>}</span></code>

3,在需要v4包的地方exclude掉annotation包,注意compile要多加个括号:

<span style="font-size:18px;"><code class="hljs ruby has-numbering"> compile (<span class="hljs-string">'com.android.support:support-v4:22.2.1'</span>){        exclude <span class="hljs-class"><span class="hljs-keyword">module</span>: '<span class="hljs-title">support</span>-<span class="hljs-title">annotations</span>'</span>    }</code><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">用v4包的地方都要这么设置下。 </span></span>

4,在application的build.gradle里的dexOptions设置里增加一句:preDexLibraries = false就ok了:
Android Studio:Multiple dex files define Landroid/support/annotation/AnimRes_第1张图片


我进行了一下设置就ok了。如下图


Android Studio:Multiple dex files define Landroid/support/annotation/AnimRes_第2张图片



PS:以上四种方法都可以解决问题,推荐正统的方法1和偷懒的方法4。



更多相关文章

  1. Android读取文件方法总结
  2. Android中Intent传递对象的两种方法(Serializable,Parcelable)!
  3. Mac安装android studio后卡在building gradle project info的解
  4. appium 【已解决】Android,每次启动手机中都会安装Appium setting
  5. android 图片压缩的几种方法
  6. Android SqLite中insert()方法解析
  7. android设备调用usb外置摄像头方法及案例
  8. Android基础教程之-------Android中两种设置全屏的方法!!!

随机推荐

  1. android中获取验证码后出现60秒的倒计时
  2. Android(安卓)Native 应用程序启动 Activ
  3. Android(安卓)7.0 FileUriExposedExcepti
  4. Android(安卓)开发(二) Android(安卓)Permi
  5. 利用java实现android项目结构API文档
  6. Android(安卓)SDK 1.0 电话号码的例子(Dem
  7. android锁屏页面实践
  8. Ubuntu 编译Android若干错误及解决方法
  9. android 打开电子市场中应用的界面
  10. [Android(安卓)基础] -- ueventd.rc 处理