android - Android Studio 是否向后兼容旧 API? (具体来说,需要针对 Android Studio 3.6.3 的旧 API (27))

标签 android android-studio kotlin gradle android-gradle-plugin

Android Studio 是否向后兼容旧 API?

进一步来说,
我需要定位 API 27 与 Android Studio 3.6.3。

我无法这样做。为什么?

注意:我知道我无法发布到 Play 商店。这对我来说不是问题。

如此处所述 - https://developer.android.com/studio/releases/gradle-plugin

Although the Android plugin is typically updated in lock-step with Android Studio, the plugin (and the rest of the Gradle system) can run independent of Android Studio and be updated separately.



在升级 Gradle 部分的表格中

插件版本 3.2.0 - 3.2.1 适用于 Gradle 版本 4.6+

我的设置:

Settings.gradle

distributionUrl=https://services.gradle.org/distributions/gradle-4.9-bin.zip



在应用程序 build.grade:

SDK/构建工具设置为:

compileSdkVersion 27 buildToolsVersion "27.0.2"

minSdkVersion 27 targetSdkVersion 27



和依赖:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'com.android.support:appcompat-v7:27.1.0' i
implementation 'com.android.support:design:27.1.0'

Build.gradle(项目)
buildscript {
    ext.kotlin_version = '1.3.71'
    repositories {
        google()
        jcenter()

    }
    dependencies {

       classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    }
}

但我得到以下信息:

The specified Android SDK Build Tools version (27.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.



这是为什么?当然,我可以在旧版本的 AS 中使用该插件版本来定位 27。

当我构建时:

error: failed linking references. (No additional detail in logs)



注意:尝试使用更低版本的构建工具和 Android Gradle 插件(并针对更低的 api)会产生相同的错误。降级 gradle 版本也不起作用(尝试使用 4.6)

注意 2:尝试使用最新版本(接受 AS 3.6.3 默认为您提供的内容,即 gradle-5.6.4, buildToolsVersion "29.0.2")会出现以下错误。
这很容易重现 - 只需创建一个新项目(选择空 Activity 以减少依赖项),使用旧版支持库,并将编译和目标 SDK 更改为 27

.../appcompat-v7-28.0.0/res/values-v28/values-v28.xml:5:5-8:13: AAPT: error: resource android:attr/dialogCornerRadius not found.



这是否意味着您不能使用 AS 3.6.3 定位低于 28 的任何内容?如果这里的构建 block 是构建工具和 Android Gradle 插件(如上所述),AS 将在这里扮演什么角色,我可以随意选择,但没有效果?

并且只想说明:不,我不想更新到 api 28。我需要专门低于 28,而我当前的 AS 版本是 3.6.3。

难道没有出路,不得不使用旧的AS?如果是后者,那么 AS 在其中的作用是什么?

最佳答案

工具版本很大程度上独立于您的targetSdkVersion , 你不需要 buildToolsVersion "27.0.2"对于 27 的目标 SDK

编辑应用的 build.gradle 以使用现代版本的构建工具,然后设置 targetSdkVersion 27
请注意,您将无法使用它部署到 Play 商店,因为现在的最低目标是 28(截至 2020 年 5 月 13 日)来源:https://developer.android.com/distribute/best-practices/develop/target-sdk

以下是针对 sdk 27​​ 的有效应用程序模块 build.gradle 的一部分

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.mikedg.dekudeals"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

以下是项目 build.gradle 中与它一起使用的 buildscript 的一部分
buildscript {
    ext.kotlin_version = '1.3.71'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

如果上述方法不起作用,我建议考虑迁移到 androidx 库而不是旧的支持库。 https://developer.android.com/jetpack/androidx/migrate#additional_resources
我认为这不会引起问题,但不能自信地说不会

关于android - Android Studio 是否向后兼容旧 API? (具体来说,需要针对 Android Studio 3.6.3 的旧 API (27)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61781970/

相关文章:

android - 什么是现有 SQLite 数据库的完整 Android 数据库助手类?

java - 从android中的filedialog中获取图片并在imageview中显示

android.content.res.Resources$NotFoundException : Resource ID #0x7f07006e

android - 小米红米 Note 4X "Install via usb"抛出 "Insert your SIM card"

android - Kotlin 1.5.0 不适用于 Dagger 2?

android - 如何使用 kotlin 语言以编程方式从 Android 中的 SIM 卡获取手机号码?

android - 标准 Android 菜单图标,例如刷新

android - 我的 Android 应用出现奇怪的 sharedPreference 问题

android-studio - 如何在 Android Studio 中生成新的图片资源

kotlin - 在 kotlin 中更改变量内部参数的值