如何在没有R和BuildConfig的情况下发布android库

boy*_*eak 1 android gradle jcenter

我制作了一个 android 库,将其发布到 jcenter 的多个版本。但是当我使用它时,我从自己的库中找到了R和BuildConfig参考。如何避免上传R和BuildConfig。这是我的 build.gradle:

version = "2.1.3"
def siteUrl = 'https://github.com/boybeak/DelegateAdapter'
def gitUrl = 'https://github.com/boybeak/DelegateAdapter.git'
group = "com.github.boybeak"
install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                name 'DelegateAdapter'
                url siteUrl
                licenses {
                    license {
                        name 'Apache-2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'boybeak'
                        name 'gaoyunfei'
                        email 'boybeak@qq.com'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'

    exclude "**/R.class"
    exclude "**/BuildConfig.class"
}

task jar(type: Jar) {
    from 'build/intermediates/classes/release'
    exclude '**/BuildConfig.class'
    exclude '**/R.class'

}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    options.encoding "UTF-8"
    options.charSet 'UTF-8'
    failOnError false

    exclude "**/R.java"
    exclude "**/BuildConfig.java"
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir

    exclude "**/R.java"
    exclude "**/BuildConfig.java"
}

artifacts {
    archives jar
    archives javadocJar
    archives sourcesJar
}
Properties properties = new Properties()
properties.load(
    project.rootProject.file('local.properties').newDataInputStream()
)
bintray {

    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")
    configurations = ['archives']
    pkg {
        repo = "nulldreams"
        name = "adapter"                // project name in jcenter
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}
Run Code Online (Sandbox Code Playgroud)

Lou*_*CAD 6

以下是避免BuildConfig生成 Android 库的方法:

// TODO replace with https://issuetracker.google.com/issues/72050365 once released.
libraryVariants.all(Action {
    generateBuildConfigProvider.configure {
        enabled = false
    }
})
Run Code Online (Sandbox Code Playgroud)

这也适用于 Gradle Kotlin DSL。

R当你没有任何资源时,我不知道有什么方法可以防止生成该类。如果您找到方法,请发表评论。