Android开发中常见错误及其解决方法
1、Warning:Conflict with dependency ‘com.google.code.findbugs:jsr305’. Resolved versions for app (3.0.1) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
这个是库依赖的版本冲突问题,可以使用强制统一依赖版本,在build.gradle中添加如下代码:
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.localgo.myapplication2"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//强制添加如下代码
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
2、所有的后台Java文件的R变成红色,提示“cannot resolve symbol R”
依次点击 Build -> Rebuild Project and then click Tools -> Android -> Sync Project with Gradle Files.
3、Could not find com.android.tools.build
3.0.0-alpha1
提示:A problem occurred configuring root project ‘Android-app’. Could not resolve all dependencies for configuration ‘:classpath’. Could not find com.android.tools.build3.0.0-alpha1. Searched in the
following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.jar
Required by:
更换gradle库地址,在build.gradle中
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
...
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
欢迎大家关注DataLearner官方微信,接受最新的AI技术推送
