gpt4 book ai didi

java - RxJava noClassDefFoundError : rx. plugins.RxJavaPlugins on API 16

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:21:23 25 4
gpt4 key购买 nike

我正在使用 RxJava 和 Retofit 开发一个 Android 应用程序。当我在 API 23 上测试我的代码时,我没有收到任何错误,但是当我在 API 15 中测试时,我的 RxJava 似乎无法正常工作,我的应用程序因错误而崩溃:

FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at $Proxy1.createToken(Native Method)
at com.loginsignup.presenter.LoginPresenterImpl.tryToLogin(LoginPresenterImpl.java:39)
at com.loginsignup.view.LoginActivity.tryToLogin(LoginActivity.java:197)
at com.loginsignup.view.LoginActivity.onClick(LoginActivity.java:180)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: rx.plugins.RxJavaPlugins
at rx.Observable.<clinit>(Observable.java:63)
at $Proxy1.createToken(Native Method)
at com.gooroo.gooroo.loginsignup.presenter.LoginPresenterImpl.tryToLogin(LoginPresenterImpl.java:39)
at com.gooroo.gooroo.loginsignup.view.LoginActivity.tryToLogin(LoginActivity.java:197)
at com.gooroo.gooroo.loginsignup.view.LoginActivity.onClick(LoginActivity.java:180)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

这是我的 gradle 构建:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.example.ex"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "0.1 alpha"
multiDexEnabled true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

dexOptions {
javaMaxHeapSize "4g"
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
compile files('libs/sinch-android-rtc-3.9.5.jar')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
compile 'com.github.orhanobut:logger:1.12'
compile 'com.viewpagerindicator:library:2.4.1@aar'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.stripe:stripe-android:+'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3@aar'
compile 'com.amazonaws:aws-android-sdk-core:2.+'
compile 'com.amazonaws:aws-android-sdk-s3:2.+'
compile 'com.google.android.gms:play-services-wallet:8.4.0'
compile 'com.android.support:multidex:1.0.0'
}

apply plugin: 'com.google.gms.google-services'

知道为什么在 API 23 上没有问题,但是当我在 API 16 上运行它时,当我尝试使用 RxJava 登录时它崩溃了吗?

最佳答案

这里的问题可能是你没有初始化 MultiDex Option

对 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. This is the reason why your app is working fine on API level 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.0'
}

在您的 list 中,将 multidex 支持库中的 MultiDexApplication 类添加到应用程序元素。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
// This will solved the problem
android:name="YourAppName">
...
</application>
</manifest>

这就是我解决问题的方法,即使存在关于相同问题的已关闭 Git 问题。

编辑

public class YouAppName extends MultiDexApplication {
.. ..
}

希望对您有所帮助。

关于java - RxJava noClassDefFoundError : rx. plugins.RxJavaPlugins on API 16,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37619596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com