问题描述
我是android开发的新手,根据文档,我从一个在线购买的项目开始从头开始开发,遇到一个错误,说未找到'app'的任何变体。检查构建文件,以确保至少存在一个变体。
这是build.gradle代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsversion "29.0.1"
defaultConfig {
applicationId "com.app-10.app"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
}
}
}
dependencies {
implementation filetree(include: ['*.jar'],dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Third Party Libraries
//Glide library for image fetching from the web
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//Material library for styling blocks
implementation 'com.google.android.material:material:1.0.0'
// Google Gson
implementation 'com.google.code.gson:gson:2.8.5'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
// Android-SpinKit
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
implementation files('libs/YouTubeAndroidplayerApi.jar')
// gotev/android-upload-service
implementation "net.gotev:uploadservice:3.5.2"
//A fast circular ImageView perfect for profile images
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'org.apache.commons:commons-io:1.3.2'
}
解决方法
我刚刚解决了类似的问题:
工具-> SDK管理器
验证是否已检查用于 Android 10.0 的SDK平台程序包(具有 API级别29 的程序包,就像您在gradle文件中定义的一样)。 如果没有,请检查并应用更改。接受许可条款,安装软件包,然后文件->与Gradle文件同步项目(或再次打开项目)
,我替换为:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
在我的情况下为我的Android Studio v3.0.1:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
但最后我还是通过
解决了您需要检测并设置正确的sdk
在我安装29.0.2之后,我的SDK为30.0.2,该错误消失了
,进入SDK管理器(Ctrl+Shift+A然后编写SDK管理器),安装当前项目的android版本,本例中我安装了从5.0开始的所有可用选项
,就我而言,这是因为我添加了 flavourDimensions
而没有将其添加到任何 productFlavors
我的案例中的示例,我在应用级别的 build.gradle
中有:
flavorDimensions "stage","mode"
还有我的productFlavors
:
productFlavors {
dev {
dimension "stage"
//noinspection DevModeObsolete
minSdkVersion 21
versionNameSuffix "-dev"
applicationIdSuffix '.dev'
resConfigs "en","xxhdpi"
}
prod {
dimension "stage"
minSdkVersion 21
versionNameSuffix "-prod"
applicationIdSuffix '.prod'
}
}
正如您在此处看到的,我没有在我的任何 flavorDimensions
中使用 productFlavors
"mode"。所以,当我尝试同步我的 gradle 时。它给了我那个错误
可能对某人有所帮助,就我而言,我只需要更新 Gradle。
Android Studio 弹出警告,所以我更新了它,然后正常工作??♀️