代码之家  ›  专栏  ›  技术社区  ›  X09

如何在我启动应用程序时修复此异常的NoClassDefFoundError

  •  0
  • X09  · 技术社区  · 8 年前

    我的Android应用程序发生了奇怪的崩溃。事情就是这样:

    如果我将应用程序发送到手机(说通 蓝牙、Xender或通过电子邮件发送给我的朋友),我启动了它,应用程序在没有晚上启动的情况下崩溃。它甚至不显示初始屏幕。只需点击启动器图标,应用程序就会崩溃。然而,如果我从Android Studio启动应用程序(即构建并运行),它不会崩溃。如果我完全卸载该应用程序(在从Android Studio运行后)并通过蓝牙或Xender发送,它的崩溃时间会更长。

    到目前为止,我已经能够在Kitkat上重现此错误,但在Lollipop+上无法重现。

    请注意,我的应用程序正在调试版本中。

    这是应用程序生成的崩溃数据:

    08-26 05:32:52.865 1630-1630/com.ozuf.poster W/dalvikvm: VFY: unable to resolve static field 20 (applicationId) in Lcom/android/tools/fd/runtime/AppInfo;
    08-26 05:32:52.865 1630-1630/com.ozuf.poster D/dalvikvm: VFY: replacing opcode 0x62 at 0x0016
    08-26 05:32:52.865 1630-1630/com.ozuf.poster W/dalvikvm: VFY: unable to resolve static field 19 (applicationClass) in Lcom/android/tools/fd/runtime/AppInfo;
    08-26 05:32:52.865 1630-1630/com.ozuf.poster D/dalvikvm: VFY: replacing opcode 0x62 at 0x0001
    08-26 05:32:52.869 1630-1630/com.ozuf.poster W/dalvikvm: VFY: unable to resolve static field 22 (usingApkSplits) in Lcom/android/tools/fd/runtime/AppInfo;
    08-26 05:32:52.869 1630-1630/com.ozuf.poster D/dalvikvm: VFY: replacing opcode 0x63 at 0x0000
    08-26 05:32:52.869 1630-1630/com.ozuf.poster W/dalvikvm: VFY: unable to resolve static field 22 (usingApkSplits) in Lcom/android/tools/fd/runtime/AppInfo;
    08-26 05:32:52.869 1630-1630/com.ozuf.poster D/dalvikvm: VFY: replacing opcode 0x63 at 0x0002
    08-26 05:32:52.869 1630-1630/com.ozuf.poster I/dalvikvm: DexOpt: unable to optimize static field ref 0x0013 at 0x1b in Lcom/android/tools/fd/runtime/BootstrapApplication;.<init>
    08-26 05:32:52.869 1630-1630/com.ozuf.poster I/dalvikvm: DexOpt: unable to optimize static field ref 0x0013 at 0x1d in Lcom/android/tools/fd/runtime/BootstrapApplication;.createRealApplication
    08-26 05:32:52.869 1630-1630/com.ozuf.poster I/dalvikvm: DexOpt: unable to optimize static field ref 0x0013 at 0x2a in Lcom/android/tools/fd/runtime/BootstrapApplication;.createRealApplication
    08-26 05:32:52.869 1630-1630/com.ozuf.poster I/dalvikvm: DexOpt: unable to optimize static field ref 0x0014 at 0x15 in Lcom/android/tools/fd/runtime/BootstrapApplication;.onCreate
    08-26 05:32:52.873 1630-1630/com.ozuf.poster I/dalvikvm: DexOpt: unable to optimize static field ref 0x0014 at 0x45 in Lcom/android/tools/fd/runtime/BootstrapApplication;.onCreate
    08-26 05:32:52.873 1630-1630/com.ozuf.poster I/dalvikvm: DexOpt: unable to optimize static field ref 0x0014 at 0x6f in Lcom/android/tools/fd/runtime/BootstrapApplication;.onCreate
    08-26 05:32:52.873 1630-1630/com.ozuf.poster I/dalvikvm: DexOpt: unable to optimize static field ref 0x0014 at 0x99 in Lcom/android/tools/fd/runtime/BootstrapApplication;.onCreate
    08-26 05:32:52.873 1630-1630/com.ozuf.poster D/AndroidRuntime: Shutting down VM
    08-26 05:32:52.873 1630-1630/com.ozuf.poster W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4cacb20)
    08-26 05:32:52.873 1630-1630/com.ozuf.poster E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.ozuf.poster, PID: 1630
                                                                       java.lang.NoClassDefFoundError: com.android.tools.fd.runtime.AppInfo
                                                                           at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:231)
                                                                           at android.app.Application.attach(Application.java:181)
                                                                           at android.app.Instrumentation.newApplication(Instrumentation.java:991)
                                                                           at android.app.Instrumentation.newApplication(Instrumentation.java:975)
                                                                           at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
                                                                           at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
                                                                           at android.app.ActivityThread.access$1500(ActivityThread.java:135)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:136)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                           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:785)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                           at dalvik.system.NativeStart.main(Native Method)
    08-26 05:33:28.765 1630-1630/com.ozuf.poster I/Process: Sending signal. PID: 1630 SIG: 9
    

    项目等级

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.1.3'
            classpath 'com.google.gms:google-services:3.0.0'
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    allprojects {
        repositories {
            jcenter()
        }
    }
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    
    dependencies {
    }
    

    应用程序分级

    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' }
    }
    
    apply plugin: 'android-apt'
    
    android {
        compileSdkVersion 23
        buildToolsVersion '24.0.0'
        defaultConfig {
            applicationId "com.ozuf.poster"
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 17
            versionName '0.17.5 Alpha'
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        productFlavors {
        }
    }
    
    
    dependencies {
        compile project(':volley')
        compile fileTree(include: ['*.jar'], dir: 'libs')
        testCompile 'junit:junit:4.12'
        apt 'com.jakewharton:butterknife-compiler:8.2.1'
        compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
            transitive = true;
        }
        compile('com.crashlytics.sdk.android:answers:1.3.9@aar') {
            transitive = true;
        }
        compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
        compile 'org.jsoup:jsoup:1.9.2'
        compile 'com.android.support:support-v4:23.4.0'
        compile 'com.android.support:appcompat-v7:23.4.0'
        compile 'com.android.support:design:23.4.0'
        compile 'com.android.support:cardview-v7:23.4.0'
        compile 'com.android.support:recyclerview-v7:23.4.0'
        compile 'com.google.firebase:firebase-core:9.0.2'
        compile 'com.google.firebase:firebase-ads:9.0.2'
        compile 'com.jakewharton:butterknife:8.2.1'
        compile 'org.greenrobot:eventbus:3.0.0'
        compile 'com.android.support:customtabs:23.4.0'
    } 
    
    apply plugin: 'com.google.gms.google-services'
    

    Android清单.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.ozuf.poster">
    
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.READ_LOGS"/>
    
        <application
            android:name=".activities.MyApplication"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <receiver
                android:name=".receivers.MyReceiver"
                android:enabled="true">
            </receiver>
    
            <provider
                android:name=".utils.SuggestionProvider"
                android:authorities="com.ozuf.poster.utils.SuggestionProvider"/>
    
            <activity
                android:name=".activities.SplashActivity"
                android:theme="@style/SplashTheme">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
    
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
                <intent-filter>
                    <action android:name="android.intent.action.VIEW"/>
    
                    <category android:name="android.intent.category.DEFAULT"/>
                    <category android:name="android.intent.category.BROWSABLE"/>
    
                    <data
                        android:host="www.ozuflink.com"
                        android:pathPrefix="/20"
                        android:scheme="http"/>
                    <data
                        android:host="www.ozuflink.com"
                        android:pathPrefix="/20"
                        android:scheme="https"/>
                    <data
                        android:host="ozuflink.com"
                        android:pathPrefix="/20"
                        android:scheme="http"/>
                    <data
                        android:host="ozuflink.com"
                        android:pathPrefix="/20"
                        android:scheme="https"/>
                    <data
                        android:host="www.ozuflink.com"
                        android:pathPrefix="/rocks"
                        android:scheme="http"/>
                    <data
                        android:host="www.ozuflink.com"
                        android:pathPrefix="/rocks"
                        android:scheme="https"/>
                    <data
                        android:host="ozuflink.com"
                        android:pathPrefix="/rocks"
                        android:scheme="http"/>
                    <data
                        android:host="ozuflink.com"
                        android:pathPrefix="/rocks"
                        android:scheme="https"/>
                </intent-filter>
            </activity>
            <activity
                android:name=".activities.MainActivity"
                android:label="@string/app_name"
                android:theme="@style/AppTheme.NoActionBar"
                android:windowSoftInputMode="stateHidden">
            </activity>
            <activity
                android:name=".activities.PostActivity"
                android:label="@string/app_name"
                android:parentActivityName=".activities.MainActivity"
                android:windowSoftInputMode="stateHidden">
                <meta-data
                    android:name="android.support.PARENT_ACTIVITY"
                    android:value="com.ozuf.poster.activities.MainActivity"/>
            </activity>
            <activity
                android:name=".activities.SettingsActivity"
                android:label="@string/title_activity_settings"
                android:parentActivityName=".activities.MainActivity"
                android:theme="@style/AppTheme">
                <meta-data
                    android:name="android.support.PARENT_ACTIVITY"
                    android:value="com.ozuf.poster.activities.MainActivity"/>
    
                <intent-filter>
                    <action android:name="android.intent.action.MANAGE_NETWORK_USAGE"/>
    
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
            </activity>
            <activity
                android:name=".activities.AboutActivity"
                android:label="@string/title_activity_about"
                android:parentActivityName=".activities.MainActivity"
                android:theme="@style/AppTheme">
                <meta-data
                    android:name="android.support.PARENT_ACTIVITY"
                    android:value="com.ozuf.poster.activities.MainActivity"/>
            </activity>
            <activity
                android:name=".activities.StoreActivity"
                android:label="@string/title_activity_store"
                android:theme="@style/StoreTheme">
            </activity>
            <activity
                android:name=".activities.SearchResultsActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:theme="@style/AppTheme">
                <intent-filter>
                    <action android:name="android.intent.action.SEARCH"/>
                </intent-filter>
    
                <meta-data
                    android:name="android.app.searchable"
                    android:resource="@xml/searchable"/>
            </activity>
            <activity
                android:name=".activities.QSettingsActivity"
                android:label="@string/title_activity_qsettings">
            </activity>
            <activity
                android:name=".activities.fSettingsActivity"
                android:label="@string/title_activity_f_settings">
            </activity>
        </application>
    
    </manifest>
    

    2 回复  |  直到 8 年前
        1
  •  1
  •   JAAD    8 年前

    听起来像是即时跑步问题。

    请禁用即时运行并尝试干净的构建。

    它应该有效

        2
  •  0
  •   Dinesh Saini    8 年前

    你的年级里的关系库

    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    

    compile 'com.android.support:support-v4:24.0.0-alpha1'
    compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
    compile 'com.android.support:design:24.0.0-alpha1'