Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gralde7.x兼容性匹配,替换build.gralde文件内容即可,可以使用的点个赞 #6

Open
evan0204 opened this issue Feb 27, 2023 · 0 comments

Comments

@evan0204
Copy link

evan0204 commented Feb 27, 2023

复制一下全部内容即可

// android/build.gradle

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
}
}
}

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

// Matches values in recent template from React Native 0.59 / 0.60
// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L5-L9
// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L5-L9
def DEFAULT_COMPILE_SDK_VERSION = 31
def DEFAULT_BUILD_TOOLS_VERSION = "31.0.0"
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 31

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}

repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
jcenter()
}

dependencies {
// ref:
// https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

afterEvaluate {
//发布的 jar 包配置
publishing{
publications{
release(MavenPublication) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

            groupId = "com.reactlibrary.clearcache"
            artifactId = packageJson.name
            version = packageJson.version
            //aar 文件
            def projectName = project.getName()
            artifact "build/outputs/aar/${projectName}-release.aar"

            pom.withXml{
                def dependenciesNode = asNode().appendNode("dependencies")
                configurations.implementation.allDependencies.forEach(){
                    Dependency dependency ->
                        if (dependency.version != "unspecified" && dependency.name != "unspecified"){
                            def dependencyNode = dependenciesNode.appendNode('dependency')
                            dependencyNode.appendNode('groupId', dependency.group)
                            dependencyNode.appendNode('artifactId', dependency.name)
                            dependencyNode.appendNode('version', dependency.version)
                        }
                }
            }
        }
    }   
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant