我使用此library并想将targetSdkVersion增加到24,并想通过添加到顶层build.gradle文件来进行此更改,我该怎么做?

我将build.gradle文件更改为此,但它给了我:找不到AndroidManifest

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

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.2'
        }
    }
    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion '24.0.2'
        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 24
            versionCode 1411005
            versionName "14.1.1-RC-5"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        sourceSets {

        }
    }

    allprojects {
        repositories {
            jcenter()
        }
    }

最佳答案

添加顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

在build.gradle(项目根目录)文件中添加以下内容。

ext {
    configuration = [
            appName          : "app_Name",
            applicationId    : "com.xx.xxx.app",
            minSdkVersion    : 14,
            targetSdkVersion : 24,
            compileSdkVersion: 24,
            versionCode      : 6,
            versionName      : "1.3.6",
            buildToolsVersion: "23.0.3",
    ]

    libraries = [
            supportVersion: "24.2.1"
    ]
}

在模块中
def appConfig = rootProject.ext.configuration;
def libs = rootProject.ext.libraries;


dependencies {
    compile project(':multiselect')
    compile "com.android.support:appcompat-v7:${libs.supportVersion}"

    }

例如

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

ext {
    configuration = [
            appName          : "app name",
            applicationId    : "com.xx.xx.app",
            minSdkVersion    : 14,
            targetSdkVersion : 24,
            compileSdkVersion: 24,
            versionCode      : 6,
            versionName      : "1.3.6",
            buildToolsVersion: "23.0.3",
    ]

    libraries = [
            supportVersion: "24.2.1"
    ]
}

buildscript {
    repositories {
        jcenter()  // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }

    task checkstyle(type: Checkstyle) {
        showViolations = true
        configFile file("../config/checkstyle/checkstyle.xml")

        source 'src/main/java'
        include '**/*.java'
        exclude '**/gen/**'
        exclude '**/R.java'
        exclude '**/BuildConfig.java'

        // empty classpath
        classpath = files()
    }
}

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

应用Gradle
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'

def appConfig = rootProject.ext.configuration;
def libs = rootProject.ext.libraries;

android {

    compileSdkVersion appConfig.compileSdkVersion
    buildToolsVersion appConfig.buildToolsVersion

    defaultConfig {
        applicationId appConfig.applicationId
        minSdkVersion appConfig.minSdkVersion
        targetSdkVersion appConfig.targetSdkVersion
        versionCode appConfig.versionCode
        versionName appConfig.versionName
        signingConfig signingConfigs.config
    }

    buildTypes {
        release {

        }
        debug {

        }
    }
    productFlavors {
    }
}

dependencies {
    compile project(':multiselect')
    compile "com.android.support:appcompat-v7:${libs.supportVersion}"
    compile "com.android.support:cardview-v7:${libs.supportVersion}"
    compile "com.android.support:recyclerview-v7:${libs.supportVersion}"
    compile "com.android.support:design:${libs.supportVersion}"
}

模块 Gradle
apply plugin: 'com.android.library'


def appConfig = rootProject.ext.configuration;
def libs = rootProject.ext.libraries;

android {
    compileSdkVersion appConfig.compileSdkVersion
    buildToolsVersion appConfig.buildToolsVersion

    defaultConfig {
        minSdkVersion appConfig.minSdkVersion
        targetSdkVersion appConfig.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile "com.android.support:appcompat-v7:${libs.supportVersion}"
    compile "com.android.support:design:${libs.supportVersion}"
}

For more about Configure Your Build

10-05 22:59
查看更多