添加新活动会破坏Android Studio中的gradle文件

时间:2017-05-27 08:43:30

标签: android android-studio android-gradle

我的Android Studio 2.3.1出现问题:当我向项目添加新活动时,我的gradle文件已损坏。 以下是我的正常.gradle文件;

apply plugin: 'com.android.application'

ext.versionMajor = 0
ext.versionMinor = 0
ext.versionPatch = 1
ext.versionClassifier = ""
ext.minimumSdkVersion = 18

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.test.android"
        minSdkVersion project.ext.minimumSdkVersion
        targetSdkVersion 24
        versionCode generateVersionCode()
        versionName generateVersionName()

        // enable multi dex support
        //multiDexEnabled true

        // FOR TEST
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // FOR TEST
    packagingOptions {
        exclude 'LICENSE.txt'
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    //testInstrumentationRunner "com.vancosys.betterkey.MockTestRunner"
}

private Integer generateVersionCode() {
    return ext.minimumSdkVersion * 10000000 + ext.versionMajor * 10000 + ext.versionMinor * 100 + ext.versionPatch
}

private String generateVersionName() {
    String versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
    if (ext.versionClassifier != null && !ext.versionClassifier.isEmpty()) {
        versionName = versionName + "" + ext.versionClassifier
    }
    return versionName;
}

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

    /**
     * FOR UNIT TEST
     */
    // Required -- JUnit 4 framework
    testCompile 'junit:junit:4.12'
    // Optional -- Mockito framework
    testCompile 'org.mockito:mockito-core:1.10.19'

    /**
     * FOR INSTRUMENTATION TEST
     */
    androidTestCompile 'com.android.support:support-annotations:25.3.1'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    // Optional -- Hamcrest library -- Set this dependency if you want to use the Hamcrest matcher library
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
    // Optional -- UI testing with Espresso
    //androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    // If your build configuration includes a compile dependency for the support-annotations library and
    // an androidTestCompile dependency for the espresso-core library,
    // your build might fail due to a dependency conflict.
    // To resolve, update your dependency for espresso-core as follows:
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    // Optional -- UI testing with UI Automator
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'

    // Database, ORM
    compile 'com.github.satyan:sugar:1.4'

    // Field and method binding
    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

    // provides a simple way to add a draggable sliding up panel
    compile 'com.sothree.slidinguppanel:library:3.3.1'

    // awesome bottom sheet
    compile 'com.github.rubensousa:bottomsheetbuilder:1.6.0'

    // awesome search view
    /*compile 'com.miguelcatalan:materialsearchview:1.4.0'*/
    compile project(path: ':materialsearchview')
}

以下是添加新活动后的.gradle文件;

apply plugin: 'com.android.application'

ext.versionMajor = 0
ext.versionMinor = 0
ext.versionPatch = 1
ext.versionClassifier = ""
ext.minimumSdkVersion = 18

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.test.android"
        minSdkVersion project.ext.minimumSdkVersion
        targetSdkVersion 24
        versionCode generateVersionCode()
        versionName generateVersionName()

        // enable multi dex support
        //multiDexEnabled true

        // FOR TEST
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // FOR TEST
    packagingOptions {
        exclude 'LICENSE.txt'
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    //testInstrumentationRunner "com.vancosys.betterkey.MockTestRunner"
}

private Integer generateVersionCode() {
    return ext.minimumSdkVersion * 10000000 + ext.versionMajor * 10000 + ext.versionMinor * 100 + ext.versionPatch
}

private String generateVersionName() {
    String versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
    if (ext.versionClassifier != null && !ext.versionClassifier.isEmpty()) {
        versionName = versionName + "" + ext.versionClassifier
    }
    return versionName;
}

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

    /**
     * FOR UNIT TEST
     */
    // Required -- JUnit 4 framework
    // Optional -- Mockito framework


    /**
     * FOR INSTRUMENTATION TEST
     */
    // Optional -- Hamcrest library -- Set this dependency if you want to use the Hamcrest matcher library
    // Optional -- UI testing with Espresso
    //androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    // If your build configuration includes a compile dependency for the support-annotations library and
    // an androidTestCompile dependency for the espresso-core library,
    // your build might fail due to a dependency conflict.
    // To resolve, update your dependency for espresso-core as follows:
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    // Optional -- UI testing with UI Automator


    // Database, ORM

    // Field and method binding

    // provides a simple way to add a draggable sliding up panel

    // awesome bottom sheet

    // awesome search view
    /*compile 'com.miguelcatalan:materialsearchview:1.4.0'*/
    compile project(path:
    ':materialsearchview')
compile
    'com.android.support:appcompat-v7:25.3.1'compile
    'com.android.support:design:25.3.1'compile
    'com.android.support:cardview-v7:25.3.1'compile
    'com.github.satyan:sugar:1.4'compile
    'com.jakewharton:butterknife:8.5.1'compile 'com.sothree.slidinguppanel:library:3.3.1'
    compile 'com.github.rubensousa:bottomsheetbuilder:1.6.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    androidTestCompile 'com.android.support:support-annotations:25.3.1'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}

如您所见,它已损坏,并在消息面板中显示此错误;

Error:(93, 0) Could not get unknown property 'compile' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

有人有任何想法吗?!

1 个答案:

答案 0 :(得分:0)

是的... Android Studio bug Here is the difference between the files 如你所见,它会混淆依赖关系:

'com.android.support:appcompat-v7:25.3.1' compile  

----应该是---->

compile 'com.android.support:appcompat-v7:25.3.1'