安转Android Studio 3.4,新建的工程模板并不能正常编译通过,需要进行一些设定。
1. 新建的工程模板后,自动进行Sync(下载junit等的依赖库失败),会有如下错误:
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not download junit.jar (junit:junit:4.12)
Show Details
Affected Modules: app
对应方法有两个:
方法1。如果不需要junit,在build.gradle中注掉即可:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//testImplementation 'junit:junit:4.12'
//androidTestImplementation 'androidx.test:runner:1.2.0'
//androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
再次Sync成功。build成功。
方法2。在build.gradle(project)中加入mavenCentral()就没问题了
buildscript { repositories { google() mavenCentral() jcenter() } } allprojects { repositories { google() mavenCentral() jcenter() } }
2. 运新安卓模拟器,出现错误:
ERROR: This AVD's configuration is missing a kernel file! Please ensure the file "kernel-ranchu" is in the same location as your system image.
解决方法:
确认模拟器配置的是当前选择安卓版本,X86模拟器。