twist twist - 2 months ago 159
Android Question

why my android studio on mac os report so many error! but app works well

I use android studio on my mac os to create an empty activity, and just run it.
The app can setup and work well.But logcat reports many errors.

Just like this as below:

09-15 06:24:43.847 7857-7857/com.home.ating.test E/InstantRun: Could not find slices in APK; aborting.
09-15 06:24:43.857 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.857 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.857 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.857 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.857 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.857 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.857 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.867 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.877 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.877 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.877 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.home.ating.test.MainActivity.access$super
09-15 06:24:43.927 7857-7857/com.home.ating.test E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering


and my build.gradle :

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
applicationId "com.home.ating.test"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
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:24.2.0'
}


I don't know how to deal with it? how can I eliminate these errors´╝č
My android emulator version is 4.4.

Answer

Most likely the classes your compiler is unable to find are not present on the (Android Studio or Genymotion) emulator (or device) because the emulator (or device) runs a version of Android older than the version which introduced these classes for the first time. Since your app is running fine, you can assume that, in the code, those classes are used on paths with conditional clauses (if, switch, ternary, etc.) that are not entered during runtime, for example:

if(android.os.Build.VERSION.SDK_INT < someThreshold) {
    doOneThing(); // not involving the missing class
} else {
    doAnother(); // involving a class in question
}

You can test whether this is the correct answer by switching to an emulator with a recent Android version (6.0 or so).