Android - 将 compileSdkVersion 更改为 16 会导致编译错误 (gradle)
Android - changing compileSdkVersion to 16 leads to compilation errors (gradle)
刚刚在 Studio 中创建了一个新的 Android 应用程序,我将 compileSdkVersion 和 minSdkVersion 设置为 16,因为我想确保我不使用 Android 更高版本中的任何功能事故.
但是,我的 build.gradle 中的这一行在更改这些后似乎会导致编译错误:
compile 'com.android.support:appcompat-v7:23.0.0'
我把它注释掉,编译就成功了。我不需要这条线吗? ActionBar等我觉得很有必要
我是否有错误的想法将 compileSdkVersion 更改为 16 以确保我不使用新功能?
我相信你想支持 sdk 版本 16+,为此,只需将 minSdkVersion 设置为 16 并使用最新的 compileSdkVersion,即 23
通过这样做,如果您使用版本 17+ 中引入的新功能,error/warning 将在编译时或在 Android Studio 中编辑代码时显示。
编辑:更多细节
你应该这样做的原因之一,因为你的代码中可以有这样的东西:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
实际上这也是支持库的工作方式。
http://developer.android.com/training/basics/supporting-devices/platforms.html
您应该将 Android SDK 平台 更新到最新的 Android 6.0 API 23.
我遇到了同样的问题,因为我只是从 SDK 管理器更新了支持库,而没有更新 SDK 平台。
(来源:techentice.com)
或者 'com.android.support:appcompat-v7:22.2.1'
而不是下载SDK平台
However, this line in my build.gradle seems to lead to compilation errors after changing these:
compile 'com.android.support:appcompat-v7:23.0.0'
这是因为支持库 v23 需要 API23 来编译项目。
在您的 build.gradle
中将 compileSdkVersion
更改为 23。
compileSdkVersion 23
When I comment it out, compilation will be successful. Do I not need this line? I thought it was necessary for ActionBar, etc.
使用 minsdk=16 我建议您使用 appcompat 库。像工具栏这样的小部件,以及所有 design support library(CollapsingToolbar、Snackbar...)都需要 appCompat。
此外,如果您想在 api16 中向后移植 material 设计,则需要它。
如果你想用最新版本编译,而不是更新和安装你的 SDK 到最新版本 API 23.
如果您真的想在 API 16 上编译和提供您的应用程序支持并且不想添加对更高版本的支持(这对我来说没有意义可能对您有好处)然后根据对你的声明
I set compileSdkVersion and minSdkVersion to 16, because I want to
make sure that I don't use any features in later versions of Android
然后设置compileSdkVersion为16,minSdkVersion为16,targetSdkVersion为16
& dependencies as compile 'com.android.support:appcompat-v6:16.0.0'
检查 SDK 中的 API 16 部分。应该是安装
而你build.gradle应该是这样的
apply plugin: 'com.android.application'
android {
compileSdkVersion 16
buildToolsVersion "16.0.0"
defaultConfig {
applicationId "com.example.inzi.mapofcontacts"
minSdkVersion 16
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v6:16.0.0'
}
根据你的问题,可能对你有帮助。
刚刚在 Studio 中创建了一个新的 Android 应用程序,我将 compileSdkVersion 和 minSdkVersion 设置为 16,因为我想确保我不使用 Android 更高版本中的任何功能事故.
但是,我的 build.gradle 中的这一行在更改这些后似乎会导致编译错误:
compile 'com.android.support:appcompat-v7:23.0.0'
我把它注释掉,编译就成功了。我不需要这条线吗? ActionBar等我觉得很有必要
我是否有错误的想法将 compileSdkVersion 更改为 16 以确保我不使用新功能?
我相信你想支持 sdk 版本 16+,为此,只需将 minSdkVersion 设置为 16 并使用最新的 compileSdkVersion,即 23
通过这样做,如果您使用版本 17+ 中引入的新功能,error/warning 将在编译时或在 Android Studio 中编辑代码时显示。
编辑:更多细节
你应该这样做的原因之一,因为你的代码中可以有这样的东西:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
实际上这也是支持库的工作方式。
http://developer.android.com/training/basics/supporting-devices/platforms.html
您应该将 Android SDK 平台 更新到最新的 Android 6.0 API 23.
我遇到了同样的问题,因为我只是从 SDK 管理器更新了支持库,而没有更新 SDK 平台。
(来源:techentice.com)
或者 'com.android.support:appcompat-v7:22.2.1'
而不是下载SDK平台
However, this line in my build.gradle seems to lead to compilation errors after changing these: compile 'com.android.support:appcompat-v7:23.0.0'
这是因为支持库 v23 需要 API23 来编译项目。
在您的 build.gradle
中将 compileSdkVersion
更改为 23。
compileSdkVersion 23
When I comment it out, compilation will be successful. Do I not need this line? I thought it was necessary for ActionBar, etc.
使用 minsdk=16 我建议您使用 appcompat 库。像工具栏这样的小部件,以及所有 design support library(CollapsingToolbar、Snackbar...)都需要 appCompat。
此外,如果您想在 api16 中向后移植 material 设计,则需要它。
如果你想用最新版本编译,而不是更新和安装你的 SDK 到最新版本 API 23.
如果您真的想在 API 16 上编译和提供您的应用程序支持并且不想添加对更高版本的支持(这对我来说没有意义可能对您有好处)然后根据对你的声明
I set compileSdkVersion and minSdkVersion to 16, because I want to make sure that I don't use any features in later versions of Android
然后设置compileSdkVersion为16,minSdkVersion为16,targetSdkVersion为16
& dependencies as compile 'com.android.support:appcompat-v6:16.0.0'
检查 SDK 中的 API 16 部分。应该是安装
而你build.gradle应该是这样的
apply plugin: 'com.android.application'
android {
compileSdkVersion 16
buildToolsVersion "16.0.0"
defaultConfig {
applicationId "com.example.inzi.mapofcontacts"
minSdkVersion 16
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v6:16.0.0'
}
根据你的问题,可能对你有帮助。