【问题标题】:Appcompat is not able to compile due to some version error [duplicate]由于某些版本错误,Appcompat 无法编译 [重复]
【发布时间】:2018-06-29 15:42:03
【问题描述】:

下面是我的 gradle 文件 安卓工作室正在显示此消息

所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 27.0.2、26.1.0。示例包括 com.android.support:support-compat:27.0.2 和 com.android.support:animated-vector-drawable:26.1。
应用插件:'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.t.t"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support:customtabs:26.1.0'
    implementation 'com.github.bumptech.glide:glide:4.5.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'

当我运行应用程序时,应用程序在运行时崩溃并显示以下错误 java.lang.NoSuchMethodError: 没有静态方法 getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface;在 Landroid/support/v4/content/res/ResourcesCompat 类中;或其超类(“android.support.v4.content.res.ResourcesCompat”的声明出现在 /data/app/com.example.tapesh.tapu_chat-2/base.apk)

【问题讨论】:

  • 构建工具版本是多少?
  • 实际上我已经删除了 buildtoolsversion,因为我已经将我的 android studio 更新为 3.0.1 ,所以没有要求,因为 android studio 建议我

标签: android android-appcompat


【解决方案1】:

我相信您正在使用构建工具版本 26.0.2 并且您正在使用一些支持依赖项。试试这个。

例如:

android {
    buildToolsVersion "26.0.2"

}

dependencies {

    implementation 'com.android.support:support-v4:26.0.2'
    implementation 'com.android.support:appcompat-v7:26.0.2'
    implementation 'com.android.support:recyclerview-v7:26.0.2'
    implementation 'com.android.support:support-v13:26.0.2'

}

【讨论】:

  • 我做了更改.. 然后它也不起作用
  • 请在此更改后粘贴您更新的 gradle。
  • 应用插件:'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.2" defaultConfig { applicationId "com.example.tapesh.tapu_chat" minSdkVersion 21 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
  • dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.0.2' //implementation 'com .android.support:customtabs:26.+' 实施 'com.github.bumptech.glide:glide:4.5.0' 实施 'com.android.support:design:26.0.2' 实施 'com.google.firebase:firebase -database:11.8.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1 ' }
  • 你试过在你的 gradle 中添加 'com.android.support:support-v4:26.0.2' 和 'com.android.support:support-v13:26.0.2' 吗?
【解决方案2】:

getFont() 适用于 Android 'O'(26.0.0-beta1) 版本

所以将您的构建工具版本更新为:"27.0.2"

示例:build.gradle

compileSdkVersion 27
buildToolsVersion "27.0.2"
targetSdkVersion 27

更新的依赖项:

compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:design:27.0.2'
compile 'com.android.support:customtabs:27.0.2'

Source

【讨论】:

  • 我做了更改,但仍然无法正常工作
  • 如果你有多个 buld.gradle...确保更新所有版本...并清理构建项目
猜你喜欢
  • 2021-05-22
  • 2021-10-02
  • 2017-12-23
  • 2016-07-21
  • 2014-06-27
  • 2017-06-09
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
相关资源
最近更新 更多