java.lang.NoClassDefFoundError:以下 Lollipop 版本上的 com.parse.Parse$Configuration$Builder

2024-03-10

我在我的应用程序中使用 parse.com sdk。它与 Lollipop 配合得非常好。但是当我在以下棒棒糖版本上运行该应用程序时,我收到此错误:

java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder
at com.parse.Parse.initialize(Parse.java:297)
at com.xxx.android.MyApp.onCreate(MyApp.java:16)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4747)
at android.app.ActivityThread.access$1500(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)

初始化解析时出现此错误

Parse.initialize(this); 

应用类代码:

public class MyApp extends Application {
@Override
public void onCreate() {
    super.onCreate();
    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);
    Parse.initialize(this);
}

}

我的清单代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.android">


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application
    android:name="com.xxx.android.MyApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.xxx.android.HomeActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.parse.APPLICATION_ID"
        android:value="@string/app_id" />
    <meta-data
        android:name="com.parse.CLIENT_KEY"
        android:value="@string/client_key" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/api_key" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

Gradle:

  apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.xxx.android"
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

}
dexOptions {
    incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g" 
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.12.0'
compile 'com.parse:parseui-widget-android:0.0.1'
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.marshalchen.ultimaterecyclerview:library:0.3.18'

}

我怎样才能解决这个问题?


查看您的依赖项,由于您已确认启用了 multidex,请考虑这一点(引用自官方文档):

Android 5.0之前的平台版本使用Dalvik运行时 用于执行应用程序代码。默认情况下,Dalvik 将应用程序限制为单个 每个 APK 的classes.dex 字节码文件。为了解决这个问题 限制,您可以使用 multidex 支持库。

这意味着您必须设置 multidex 支持库才能启用 multidex 并能够在运行 5.0 之前的 Android 版本的设备上运行您的应用程序。

The 官方文档 http://developer.android.com/tools/building/multidex.html#mdex-gradle非常简单,也很容易遵循。

你基本上必须:

  • 启用 multidex 支持defaultConfig部分添加:multiDexEnabled true
  • 将库声明为依赖项:

    编译'com.android.support:multidex:1.0.0'

  • 跳过需要设置的步骤MultiDexApplication在清单中作为application名字(因为你有自己的Application class).

既然你有习惯Application类,设置 multidex 支持库时请小心:

如果您的应用程序使用扩展 Application 类,您可以覆盖 AttachBaseContext() 方法并调用 MultiDex.install(this) 来启用 多索引。

所以从你的自定义中调用这个方法Application class.

请检查该库是否有新版本:如果是这种情况,Android Studio 应该向您发出警告。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java.lang.NoClassDefFoundError:以下 Lollipop 版本上的 com.parse.Parse$Configuration$Builder 的相关文章

随机推荐