更改API级别的Android Studio

本文翻译自:Changing API level Android Studio

I want to change the minimum SDK version in Android Studio from API 12 to API 14. I have tried changing it in the manifest file, ie, 我想将Android Studio中的最低SDK版本从API 12更改为API14。我尝试在清单文件中进行更改,即

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />

and rebuilding the project, but I still get the Android Studio IDE throwing up some errors. 并重建项目,但是我仍然得到Android Studio IDE抛出一些错误。 I presume I have to set the min SDK in 'project properties' or something similar so the IDE recognizes the change, but I can't find where this is done in Android Studio. 我想我必须在“项目属性”或类似的项目中设置min SDK,以便IDE能够识别更改,但是我找不到在Android Studio中完成的操作。


#1楼

参考:https://stackoom.com/question/1JfkP/更改API级别的Android-Studio


#2楼

For me what worked was: (right click)project->android tools->clear lint markers. 对我来说,有效的方法是:(右键单击)项目-> android工具->清除棉绒标记。 Although for some reason the Manifest reverted to the old (lower) minimum API level, but after I changed it back to the new (higher) API level there was no red error underline and the project now uses the new minimum API level. 尽管出于某些原因,清单已还原为旧的(较低)最低API级别,但是在我将其更改回新的(较高)API级别之后,没有出现红色错误下划线,并且该项目现在使用了新的最低API级别。

Edit: Sorry, I see you were using Android Studio, not Eclipse. 编辑:对不起,我看到您使用的是Android Studio,而不是Eclipse。 But I guess there is a similar 'clear lint markers' in Studio somewhere and it might solve the problem. 但是我想Studio中的某个地方也有类似的“清晰的棉绒标记”,这也许可以解决问题。


#3楼

As well as updating the manifest, update the module's build.gradle file too (it's listed in the project pane just below the manifest - if there's no minSdkVersion key in it, you're looking at the wrong one, as there's a couple). 在更新清单的同时, build.gradle更新模块的build.gradle文件(在清单下方的项目窗格中列出该文件-如果其中没有minSdkVersion密钥,则说明您输入的是错误的,因为有几个)。 A rebuild and things should be fine... 重建,一切都应该很好...


#4楼

When you want to update your minSdkVersion in an existent project... 当您想在现有项目中更新您的minSdkVersion时...

  1. Update build.gradle(Module: app) - Make sure is the one under Gradle Script and it is NOT build.gradle(Project: yourproject) . 更新build.gradle(Module: app) -确保是Gradle Script下的那个,而不是 build.gradle(Project: yourproject)

An example of build.gradle: build.gradle的示例:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"

    defaultConfig {
        applicationId "com.stackoverflow.answer"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dependencies {
    androidTestCompile 'junit:junit:4.12'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
  1. Sync gradle button (refresh all gradle projects also works) 同步gradle按钮 (刷新所有gradle项目也可以)

For beginners in Android Studio "Sync gradle button" is located in Tools -> Android -> Sync Project with Gradle Files "Rebuild project" Build -> Rebuild Project 对于Android Studio中的初学者,“同步gradle按钮”位于工具-> Android->使用Gradle文件同步项目“ Rebuild project” Build-> Rebuild Project

  1. Rebuild project 重建项目

After updating the build.gradle 's minSdkVersion , you have to click on the button to sync gradle file ("Sync Project with Gradle files"). 更新的build.gradle minSdkVersion ,你必须点击按钮的gradle同步文件(‘同步工程与摇篮文件’)。 That will clear the marker. 这将清除标记。

Updating manifest.xml , for eg deleting any references to SDK levels in the manifest file, is NOT necessary anymore in Android Studio. 在Android Studio中,不再需要更新manifest.xml ,例如删除清单文件中对SDK级别的任何引用。


#5楼

For android studio users: 对于android studio用户:

  1. right click the App directory 右键单击App目录
  2. choose the "module setting" option 选择“模块设置”选项
  3. change the ADK Platform as what you need 根据需要更改ADK平台
  4. Click Apply 点击应用

The gradle will rebuild the project automatically. gradle将自动重建项目。


#6楼

According to this answer , you just don't include minsdkversion in the manifest.xml, and the build system will use the values from the build.gradle file and put the information into the final apk. 根据这个答案 ,您只需要在manifest.xml中不包含minsdkversion,构建系统将使用build.gradle文件中的值并将信息放入最终apk中。

Because the build system needs this information anyway, this makes sense. 因为构建系统仍然需要此信息,所以这很有意义。 You should not need to define this values two times. 您无需两次定义该值。

You just have to sync the project after changing the build.gradle file, but Android Studio 0.5.2 display a yellow status bar on top of the build.gradle editor window to help you 您只需要在更改build.gradle文件后同步项目,但是Android Studio 0.5.2在build.gradle编辑器窗口顶部显示黄色状态栏以帮助您

Also note there at least two build.gradle files: one master and one for the app/module. 还要注意至少有两个build.gradle文件:一个主文件和一个用于应用程序/模块的文件。 The one to change is in the app/module, it already includes a property minSdkVersion in a newly generated project. 要更改的是在应用程序/模块中,它已经在新生成的项目中包含属性minSdkVersion

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值