AAPT: error: resource android:attr/fontVariationSettings not found.

安装sdk api28,安卓9.0

配置:

build.gradle(module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "36.1.0"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 26
        targetSdkVersion 28
        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(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            // 强制所有support库使用 27.1.1(匹配你的低SDK)
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.2.0'
            }
        }
    }
}

点击sync project with gradle files

image

 

 点击运行:

image

 

----------------------

打开你项目的 build.gradle (Module 级别) 文件(不是 Project 级别),修改以下 3 个版本号:

 
gradle
 
 
android {
    // 1. 把 compileSdkVersion 改成至少 28 及以上
    compileSdkVersion 28

    defaultConfig {
        // 2. targetSdkVersion 也同步改成 28 及以上
        targetSdkVersion 28
    }
}

dependencies {
    // 3. 把 support 库统一升级到 28.0.0 (和compileSdkVersion匹配)
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    // 其他所有 support 库都统一为 28.0.0
}
 
 

关键说明

 
  1. core-1.0.1 是 AndroidX 库,最低要求 compileSdkVersion ≥ 28
  2. 低版本 SDK(27 及以下)没有fontVariationSettings属性,所以报错
  3. 必须保证:compileSdkVersion ≥ 依赖库的最低要求版本
posted @ 2026-03-27 17:25  txwtech  阅读(0)  评论(0)    收藏  举报