【问题标题】:cant render because of appcompat由于 appcompat 无法渲染
【发布时间】:2018-08-11 13:34:05
【问题描述】:

我的 android studio 似乎无法正确渲染,因为 com.android.support:appcompat-v7:28.0.0-rc01 虽然我不太确定

这是显示的错误消息

所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 28.0.0-rc01、26.1.0。示例包括 com.android.support:animated-vector-drawable:28.0.0-rc01 和 com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) 有一些库或工具和库的组合是不兼容的,或者可能导致错误。一种这样的不兼容性是使用不是最新版本的 Android 支持库版本进行编译(或者特别是低于您的 targetSdkVersion 的版本)

这是我的 gradle 构建(项目)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.4'


            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
            classpath 'com.google.gms:google-services:4.0.1'
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

这是我的 gradle build(module)

//noinspection GradleCompatible
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.jbdelosreyes.finalmvp"
        minSdkVersion 19
        targetSdkVersion 28
        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:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-firestore:17.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 错误信息还应该告诉你如何让 gradle 打印整个依赖树。这将帮助您跟踪哪个库正在使用旧版本的 appcompat。

标签: android


【解决方案1】:

设置你的

compileSdkVersion to 27
targetSdkVersion to 27

还有

appCompat version to 

27.1.1

【讨论】:

  • 现在显示 Failed to resolve: com.android.support:appcompat-v7:27.1.1-rc01 并显示 gradle project sync failed
  • @AnotherJuan 请注意,这个答案说使用27.1.1,而不是27.1.1-rc01
  • 删除 -rc01 。只有 27.1.1
  • 所有 com.android.support 库必须使用完全相同的版本规范(混合版本会导致运行时崩溃)。找到版本 27.1.1、26.1.0。例子包括 com.android.support:animated-vector-drawable:27.1.1 和 com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) 有一些库的组合,或者不兼容或可能导致错误的工具和库。一种这样的不兼容性是使用不是最新版本的 Android 支持库版本进行编译(或者特别是低于您的 targetSdkVersion 的版本)。
  • 现在它这么说了。对不起,如果我造成了太多麻烦
【解决方案2】:

这更像是一种 hack,而不是 Answer。

TL;DR

发生这种情况是因为在支持 lib 28.0.0-rc01 中存在与渲染 Appcompat ActionBar 相关的错误并出现未知错误。

在 Android 团队修复错误之前如何使用设计视图?

  1. 转到应用程序 -> build.gradel 文件
  2. compileSdkVersion 27 27 不是 28
  3. targetSdkVersion 27 27 不是 28
  4. implementation 'com.android.support:appcompat-v7:27.1.1' 27.1.1 不是 28.0.0-rc01

P.S.:- 这并不意味着降级是一个好的选择或答案,但现在它是!

【讨论】:

    【解决方案3】:

    试试看 在您的构建中:

       buildscript {
    
        repositories {
        google()
        jcenter()
    }
            dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    
        // NOTE: Do not place your application 
         dependencies here; they belong
        // in the individual module build.gradle files
    }
          }
    
           allprojects {
          repositories {
        maven {
            url "https://maven.google.com"
        }
    
        maven { url 'https://jitpack.io' }
    
        google()
        jcenter()
         }
         }
    
          task clean(type: Delete) {
          delete rootProject.buildDir
           }
    

    在 Gradle.Build 中:

       apply plugin: 'com.android.application'
    
       android {
       compileSdkVersion 25
       buildToolsVersion "26.0.2"
    
        defaultConfig {
        applicationId "com.example.naser.arabic"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
        "android.support.test.runner.AndroidJUnitRunner"
         }
         buildTypes {
         release {
            minifyEnabled true
            proguardFiles 
            getDefaultProguardFile('proguard- 
            android.txt'), 'proguard-rules.pro'
            }
            }
            sourceSets { main { assets.srcDirs = 
            ['src/main/assets', 'src/main/assets/'] } }
            compileOptions {
            targetCompatibility 1.8
             sourceCompatibility 1.8
           }
           }
    
          dependencies {
          compile fileTree(include: ['*.jar'], dir: 
          'libs')
    
               androidTestCompile('
                com.android.support.test.espresso:es 
               presso-core:2.2.2', {
                  exclude group: 'com.android.support', 
            module: 
          'support-annotations'
             })
            compile 'com.android.support:appcompat- 
            v7:25.3.1'
            compile files('libs/universal-image-loader- 
            1.9.3.jar')
            compile 
             'com.android.support.constraint:constraint- 
            layout:1.0.0-alpha7'
            compile 'com.android.support:design:25.3.1'
             compile 'com.android.support:support- 
            v4:25.3.1'}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 2019-11-26
      • 2014-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多