代码之家  ›  专栏  ›  技术社区  ›  Saeed

将android studio升级到3.1.3版本后出错:AppCompatActivity类无法导入

  •  0
  • Saeed  · 技术社区  · 7 年前

    我将我的android studio表单版本2.3.3升级到3.1.3。但现在,当我第一次创建新项目时,出现了以下错误:

    Unable to resolve dependency

    这是我的版本。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.3'
    
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    这个文件也是build.gradle(模块:app):

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "giant.shoot.ir.glinter.myapplication"
            minSdkVersion 18
            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.constraint:constraint-layout:1.1.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }
    

    怎么了?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Taylor Venissat    7 年前

    您的build.gradle(模块:app)文件中缺少调试生成类型。

    改变这个

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

    为了这个

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

    Relevant Stack Overflow post for more information .

    编辑: 将此包含在build.gradle(项目:)文件中

    buildscript {
       ...
       repositories {
            mavenCentral()
            maven { url "https://maven.fabric.io/public" }
            google()
            jcenter()
        }
        ...
    }
    
    allprojects {
        repositories {
            mavenCentral()
            maven { url "https://maven.fabric.io/public" }
            google()
            jcenter()
        }
    }