1、写了简单的界面,报错
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the ‘java’ gradle plugin in a library submodule add
targetCompatibility = ‘1.7’
sourceCompatibility = ‘1.7’
to that submodule’s build.gradle file.
app的build.gradle在中添加
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
然后还是报了错,
Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
解决方案:在app的build.gradle里加三行
defaultConfig {
applicationId "com.xxx"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions { //加
enabled true //加
} //加
}
参考:http://blog.csdn.net/fullstackdeveloper/article/details/52701707
2、然后遇到问题是闪退,显示xx已经停止工作,然后看catlog是很多错误
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {com.android/activity.MainTabActivity}:
查到说是AndroidManifest.xml 配置 activity 时路径搞错了。
果然进入AndroidManifest.xml,
<activity android:name="com.myapp.test.MainActivity" >
发现只写了MainActivity,没有前面一长串,还报错了,当时没看出来,找了半天。
参看http://jakend.iteye.com/blog/1014479
3、然而还是有问题,
Could not find class ‘android.graphics.drawable.Ripple
Drawable’, referenced from method android.support.
v7.widget.AppCompatImageHelper.hasOverlappingRendering
这查了半天,最后发现是版本问题,
在app的build.gradle中查看最低版本和目标版本,结果发现模拟器用的19,程序不行,但真机已经可以,应该是版本的问题。
defaultConfig {
applicationId "com.example.a10024.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
参看http://blog.csdn.net/jiawei6212130/article/details/52302432#reply
再就是标题栏自己消失是因为继承了Activity,改成AppCompatActivity就好了。
困!但终于解决了!