android - Gradle 同步失败:原因:未指定 compileSdkVersion
问题描述
我正在尝试在 android studio 中测试我的 ionic 应用程序。它抛出以下错误。
Gradle sync failed: Cause: compileSdkVersion is not specified.
有什么解决方案吗?我究竟做错了什么。
这是我的 build.gradle 文件
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
repositories {
mavenCentral();
jcenter()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1.0'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:+'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:+'
implementation 'com.android.support:appcompat-v7:27.+'
}
解决方案
您正在使用android 支持库,27.+
因此您必须提供sdk
版本27
,否则您compileSdkVersion
的targetSdkVersion
项目不知道您的项目应该为哪个平台构建。这些参数应该在build.gradle(app)的 android 目录中给出:
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.abc.test"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
只需将此代码粘贴到此apply plugin: 'com.android.application'
行下方
推荐阅读
- javascript - 如何将返回的对象转换为带有对象的承诺?
- sql - CASE 语句和 GROUP BY 子句中的聚合函数错误
- c++ - 避免或改进蛮力方法:计算字典文本文件中所有单词的字符重复
- reactjs - 如何更改按钮状态并将操作发送到 redux?
- css - ng-select multiple - 改变高度
- javascript - 在谷歌电子表格中更新单元格时通过电子邮件通知
- java - 如何解决清单合并失败的问题?
- multithreading - 关于单主任务控制的worker任务实现的问题
- android - RxJava Chain 请求并从任何请求更新到 Observer
- batch-file - 批处理脚本 - findstr 用结果覆盖 csv 文件