android – Twitter Fabric MultiDex导致NoClassDefFoundError

android – Twitter Fabric MultiDex导致NoClassDefFoundError,第1张

概述我在我的项目中启用了Multidex支持,它在 Android 5.0及更高版本上运行良好,但是当我开始使用Android 4.3及以下版本开始测试我的应用程序时,它开始为TwitterConfig提供NoClassDefFoundError. 我无法禁用我的Multidex支持.我不知道为什么我会遇到这个问题.试图在网上找到解决方案,但没有帮助. 这是我得到的例外. java.lang.NoCl 我在我的项目中启用了MultIDex支持,它在 Android 5.0及更高版本上运行良好,但是当我开始使用AndroID 4.3及以下版本开始测试我的应用程序时,它开始为TwitterConfig提供NoClassDefFoundError.

我无法禁用我的MultIDex支持.我不知道为什么我会遇到这个问题.试图在网上找到解决方案,但没有帮助.

这是我得到的例外.

java.lang.NoClassDefFoundError: com.twitter.sdk.androID.core.TwitterauthConfig        at com.twitter.sdk.androID.core.TwitterauthConfig.<clinit>(TwitterauthConfig.java:39)        at MyApplication.onCreate(MyApplication.java:46)        at androID.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)        at androID.app.ActivityThread.handleBindApplication(ActivityThread.java:4702)        at androID.app.ActivityThread.access00(ActivityThread.java:168)        at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1389)        at androID.os.Handler.dispatchMessage(Handler.java:99)        at androID.os.Looper.loop(Looper.java:137)        at androID.app.ActivityThread.main(ActivityThread.java:5493)        at java.lang.reflect.Method.invokeNative(Native Method)        at java.lang.reflect.Method.invoke(Method.java:525)        at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)        at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:1025)        at dalvik.system.NativeStart.main(Native Method)

这是我的app.gradle

buildscript {    repositorIEs {        maven { url 'https://maven.fabric.io/public' }    }    dependencIEs {        classpath 'io.fabric.tools:gradle:1.+'    } }    apply plugin: 'com.androID.application'    apply plugin: 'io.fabric'  repositorIEs {    maven { url 'https://maven.fabric.io/public' }    mavenCentral()  }   androID {    packagingOptions {        exclude 'meta-inf/NOTICE.txt'        exclude 'meta-inf/liCENSE.txt'    }    compileSdkVersion 22    buildToolsversion "23.0.0 rc3"    defaultConfig {                    minSdkVersion 16        targetSdkVersion 22        versionCode 1        versionname "1.0"        multIDexEnabled true    }    buildTypes {        release {            MinifyEnabled false            proguardfiles getDefaultProguardfile('proguard-androID.txt'),'proguard-rules.pro'        }    }    dexOptions {        javaMaxHeapSize "2g"    }}dependencIEs {    compile filetree(dir: 'libs',include: ['*.jar'])    compile 'com.androID.support:appcompat-v7:22.2.1'           compile 'com.androID.support:multIDex:1.0.1'    compile 'com.androID.support:design:22.2.1'    compile 'com.androID.support:recyclervIEw-v7:22.2.1'    compile 'com.androID.support:cardvIEw-v7:22.2.1'    compile 'com.androID.support:support-v4:22.2.1'    compile project(':MPChartlib')    compile 'com.facebook.androID:facebook-android-sdk:4.6.0'    compile('com.crashlytics.sdk.androID:crashlytics:2.5.2@aar') {        transitive = true;    }    compile('com.twitter.sdk.androID:twitter:1.8.0@aar') {        transitive = true;    }}

这是MyApplication类中的Twitter代码.

@OverrIDepublic voID onCreate() {    super.onCreate();    //Configure twitter using Twitter key and Secret Key    TwitterauthConfig authConfig =            new TwitterauthConfig(TWITTER_KEY,TWITTER_SECRET);    // add functionalitIEs which we are using with Fabric    Fabric.with(this,new Crashlytics(),new Twitter(authConfig));    FacebookSdk.sdkInitialize(getApplicationContext());    // Initialize the SDK before executing any other operations,// especially,if you're using Facebook UI elements.}

即使我尝试了this解决方案,但没有帮助.

任何提示或参考赞赏.

解决方法 适用于AndroID 5.0及更高版本的MultIDex支持

AndroID 5.0 and higher uses a runtime called ART which natively
supports loading multiple dex files from application APK files. ART
performs pre-compilation at application install time which scans for
classes(..N).dex files and compiles them into a single .oat file for
execution by the AndroID device. For more information on the AndroID
5.0 runtime,see Introducing ART.

这意味着您的应用程序可以在API级别21或更高级别上正常运行.

AndroID 5.0之前的MultIDex支持

Versions of the platform prior to AndroID 5.0 use the Dalvik runtime
for executing app code. By default,Dalvik limits apps to a single
classes.dex bytecode file per APK. In order to get around this
limitation,you can use the multIDex support library,which becomes
part of the primary DEX file of your app and then manages access to
the additional DEX files and the code they contain.

所以,首先要确保你已经导入了正确的依赖,这似乎你做到了.

dependencIEs {  compile 'com.androID.support:multIDex:1.0.1'}

在清单中,将MultIDex支持库中的MultIDexApplication类添加到application元素中.

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.example.androID.multIDex.myapplication">    <application        ...        androID:name="androID.support.multIDex.MultIDexApplication">        ...    </application></manifest>

替代方案,如果您的应用程序扩展了Application类,您可以覆盖attachBaseContext()方法并调用MultIDex.install(this)来启用multIDex.

public voID onCreate(Bundle arguments) {    MultIDex.install(getTargetContext());    super.onCreate(arguments);    ...}

最后,您需要通过添加multIDexEnabled true来更新build.gradle文件,如下所示:

defaultConfig {          applicationID '{Project name}'          minSdkVersion 15          targetSdkVersion 23          versionCode 1          versionname "1.0"          multIDexEnabled true      }

我希望它会帮助你.

总结

以上是内存溢出为你收集整理的android – Twitter Fabric MultiDex导致NoClassDefFoundError全部内容,希望文章能够帮你解决android – Twitter Fabric MultiDex导致NoClassDefFoundError所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1137286.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存