0

大家好,我使用带有'^1.13.3'版本的react-native-reanimated,当我想发布一个apk时出现此错误;

出了什么问题:配置项目“:react-native-reanimated”时出现问题。

com.android.builder.errors.EvalIssueException:未指定 compileSdkVersion。请将它添加到 build.gradle 我的 node_modules/react-native-reanimated/android/build.gradle 文件是

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

buildscript {
    if (project == rootProject) {
        // 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.
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.2'
        }
    }
}

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

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 28)
    buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 16)
        targetSdkVersion safeExtGet('targetSdkVersion', 28)
        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 {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules
    implementation "androidx.transition:transition:1.1.0"
}

def configureReactNativePom(def pom) {
    def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

    pom.project {
        name packageJson.title
        artifactId packageJson.name
        version = packageJson.version
        group = "com.swmansion.reanimated"
        description packageJson.description
        url packageJson.repository.baseUrl

        licenses {
            license {
                name packageJson.license
                url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
                distribution 'repo'
            }
        }

        developers {
            developer {
                id packageJson.author.username
                name packageJson.author.name
            }
        }
    }
}

afterEvaluate { project ->

    task androidJavadoc(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
        classpath += files(android.bootClasspath)
        classpath += files(project.getConfigurations().getByName('compile').asList())
        include '**/*.java'
    }

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

    task androidSourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.srcDirs
        include '**/*.java'
    }

    android.libraryVariants.all { variant ->
        def compileTask
        if (variant.hasProperty('javaCompileProvider')){
            compileTask = variant.javaCompileProvider.get()
        }else{
            compileTask = variant.javaCompile
        }

        def name = variant.name.capitalize()
        task "jar${name}"(type: Jar, dependsOn: compileTask) {
            from compileTask.destinationDir
        }
    }

    artifacts {
        archives androidSourcesJar
        archives androidJavadocJar
    }

    task installArchives(type: Upload) {
        configuration = configurations.archives
        repositories.mavenDeployer {
            // Deploy to react-native-event-bridge/maven, ready to publish to npm
            repository url: "file://${projectDir}/../android/maven"

            configureReactNativePom pom
        }
    }
}
4

1 回答 1

0

您需要从 gradle-wrapper.properties 将 gradle 版本 7 降级到 6,如下所示:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip

我不知道,但它有效。

于 2022-01-26T10:40:46.310 回答