遇到个崩溃的bug,记录下解决方法:
java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout
摘自stack Overflow:
I faced the same issue and fixed it. It is issue with Dex limit. Because the dex limit is reached, it creates two dex files. Lollipop knows how to read, pre-Lollipop has no idea unless you specify it in the Application
class.
Please make sure following is in place:
in build.gradle
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
defaultConfig {
multiDexEnabled true
}
IMPORTANT to support pre-Lollipop:
In Manifest, under the application tag,
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
Or if you have used your own Application
class, make your Application
override attachBaseContext
starting with
import android.support.multidex.MultiDexApplication;
import android.support.multidex.MultiDex;
public class MyApplication extends MultiDexApplication {
// ......
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Reference: https://developer.android.com/tools/building/multidex.html#mdex-gradle