Unable to merge dex after adding dependencies

前端 未结 2 515
故里飘歌
故里飘歌 2021-01-29 00:38

I am getting the error:

Error:Execution failed for task \':app:transformDexArchiveWithExternalLibsDexMergerForPaidFreeDebug\'. java.lang.RuntimeExcepti

相关标签:
2条回答
  • 2021-01-29 01:21
    Duplicate zip entry [httpcore-4.3.2.jar:org/apache/http/annotation/NotThreadSafe.class]
    

    You are picking up two copies of this Java class, from sources that Gradle is not netting out in its dependency resolution process.

    One possibility is that one of your new dependencies has a transitive dependency on Apache HttpCore, but that libs/droidText.0.2.jar or one of your other dependencies has its own copy of org.apache.http.annotation.NotThreadSafe.

    Android Studio has the "External Libraries" portion of the project tree, if you are in the Project view (rather than the default Android view):

    Android Studio External Libraries tree

    The only way that I know of to track this down is to start sifting through your libraries and try to identify the 2+ that have org.apache.http.annotation.NotThreadSafe. Then, try to figure out how to stop using one of those. The libraries that have this class may be through transitive dependencies, and so you would also need to identify where those transitive dependencies came from. This will be painful, which is why that I am hoping that newer versions of Android Studio will be more helpful here.

    0 讨论(0)
  • 2021-01-29 01:27

    Add this to your application class..

       @Override
       protected void attachBaseContext(Context base) {
          super.attachBaseContext(LocaleHelper.onAttach(base, "hi"));
          MultiDex.install(this);
     }
    

    like :-

    also extend the MultiDexApplication by your Application class

    public class MyApplication  extends MultiDexApplication {
    
    
    
          @Override
          protected void attachBaseContext(Context base) {
               super.attachBaseContext(base);
               MultiDex.install(this);
    }
    
    
         @Override
         public void onConfigurationChanged(Configuration newConfig) {
              super.onConfigurationChanged(newConfig);
    
         }
    
    
    }
    

    Edit:- As you are using targetSdkVersion <=23 you need to install it manually.,. and dont forget to add android:name="android.support.multidex.MultiDexApplication" to your application tag in the manifest.xml.. like this :-

    <application
                android:name="android.support.multidex.MultiDexApplication" >
            ...
        </application>

    0 讨论(0)
提交回复
热议问题