安装完Android studio之后,新建第一个helloworld项目,意外的收获一枚报错,如上图所示。
经过不断的重装以及降低版本均宣告失败以后,最后我还是选择求助于大佬帮忙解决。以下是解决的全部过程:
- 首先,我更换了app包下的build.gradle文件内容
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
flavorDimensions "versionCode"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
defaultConfig {
manifestPlaceholders = [ activityLabel:"defaultName"]
}
productFlavors {
free {
}
pro {
manifestPlaceholders = [ activityLabel:"proName" ]
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
然后神奇的是,这个可爱的小东西换了一种报错方式(如下图) 结论是,还是版本的问题。
- 解决无果后,大佬建议再次修改app下的build.gradle。插入下面的代码于图中所示位置:
flavorDimensions "versionCode"
然后点右上角的Sync now 开始更新
- 更新完毕后,这个小东西又开始出别的问题(心态已经可以开始裂了),如下所示。
- 最后(终于最后了),还是如下图降低了版本,然后BUILD SUCCESSFUL~
撒花~~~
但愿在如此曲折的安卓开场之后,后面的路会稍微顺畅一点!