配置项目':react-native-audio-recorder-player'时出现问题>未指定compileSdkVersion,同时运行react-native run-android

问题描述 投票:0回答:4

每当我尝试运行react-native run-android时,我都会收到以下错误:

A problem occurred configuring project ':react-native-audio-recorder-player'.
> compileSdkVersion is not specified.

构建.gradle

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
    minSdkVersion = 21
    compileSdkVersion = 28
    targetSdkVersion = 28
    
    androidXAnnotation = "1.1.0"
    androidXBrowser = "1.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")
        classpath 'com.google.gms:google-services:4.2.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    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()
        maven { url 'https://www.jitpack.io' }
    }
}

应用程序/build.gradle

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation. If none specified and
 *   // "index.android.js" exists, it will be used. Otherwise "index.js" is
 *   // default. Can be overridden with ENTRY_FILE environment variable.
 *   entryFile: "index.android.js",
 *
 *   // https://reactnative.dev/docs/performance#enable-the-ram-format
 *   bundleCommand: "ram-bundle",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.sheolife"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
          release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
               signingConfig signingConfigs.release
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation project(':react-native-android-open-settings')
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-audio')
    implementation 'com.clevertap.android:clevertap-android-sdk:4.0.0'
    implementation 'com.google.firebase:firebase-messaging:20.2.4'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation project(':react-native-audio-recorder-player')
     compile 'com.facebook.fresco:animated-gif:1.+'
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

package.json

{
  "name": "sheolife",
  "version": "0.0.1",
  "private": true,
  "rnpm": {
    "assets": [
      "./src/assets/fonts/"
    ]
  },
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "start-web": "react-scripts start",
    "build": "react-scripts build",
    "test-web": "react-scripts test --env=jsdom",
    "eject-web": "react-scripts eject",
    "prettier": "prettier --write './src'",
    "yarn-ios": "yarn ios --simulator `iPhone 6s` --verbose",
    "clear-modules": "rm -rf node_modules; rm -f package-lock.json; rm -f yarn.lock"
  },
  "dependencies": {
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "^1.12.0",
    "@react-native-community/cameraroll": "^4.0.2",
    "@react-native-community/cli": "^4.14.0",
    "@react-native-community/clipboard": "^1.2.3",
    "@react-native-community/hooks": "^2.6.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "^6.0.0",
    "@react-native-community/voice": "^1.1.9",
    "@react-navigation/bottom-tabs": "^5.9.0",
    "@react-navigation/drawer": "^5.11.4",
    "@react-navigation/material-top-tabs": "^5.3.10",
    "@react-navigation/native": "^5.7.3",
    "@react-navigation/stack": "^5.9.0",
    "@reduxjs/toolkit": "^1.4.0",
    "@twotalltotems/react-native-otp-input": "^1.3.11",
    "axios": "^0.20.0",
    "clevertap": "^1.1.1",
    "clevertap-react-native": "^0.5.0",
    "i18n-js": "^3.8.0",
    "loadash": "^1.0.0",
    "lodash.memoize": "^4.1.2",
    "materialize-css": "^1.0.0-rc.2",
    "modal-react-native-web": "^0.2.0",
    "moment": "^2.29.1",
    "qs": "^6.9.4",
    "react": "16.13.1",
    "react-art": "^16.5.1",
    "react-datepicker": "^3.3.0",
    "react-dom": "^16.5.1",
    "react-dropdown": "^1.9.0",
    "react-materialize": "^3.9.3",
    "react-native": "0.63.2",
    "react-native-android-open-settings": "^1.3.0",
    "react-native-animated-ellipsis": "^2.0.0",
    "react-native-animated-loader": "^0.0.9",
    "react-native-audio": "^4.3.0",
    "react-native-audio-recorder-player": "^2.6.1",
    "react-native-auto-height-image": "^3.2.4",
    "react-native-calendars": "^1.1129.0",
    "react-native-countdown-component": "^2.7.1",
    "react-native-create-thumbnail": "^1.2.2",
    "react-native-custom-datetimepicker": "^3.0.0",
    "react-native-date-picker": "^3.2.8",
    "react-native-datepicker": "^1.7.2",
    "react-native-debugger": "^1.1.0",
    "react-native-dialog": "^6.1.2",
    "react-native-drawer": "^2.5.1",
    "react-native-dropdown-picker": "^3.7.1",
    "react-native-eject": "^0.1.2",
    "react-native-gesture-handler": "^1.8.0",
    "react-native-google-places-autocomplete": "^2.2.0",
    "react-native-htmlview": "^0.16.0",
    "react-native-image-base64": "^0.1.4",
    "react-native-image-crop-picker": "^0.33.2",
    "react-native-image-picker": "^3.1.4",
    "react-native-indicators": "^0.17.0",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-localize": "^2.0.1",
    "react-native-modal": "^11.6.1",
    "react-native-paper": "^4.5.0",
    "react-native-picker-select": "^8.0.3",
    "react-native-picker-view": "^1.0.9",
    "react-native-pie": "^1.1.2",
    "react-native-pie-chart": "^1.0.13",
    "react-native-progress-bar-animated": "^1.0.6",
    "react-native-progress-circle": "^2.1.0",
    "react-native-pull-to-refresh": "^2.1.3",
    "react-native-range-slider": "^0.1.2",
    "react-native-raw-bottom-sheet": "^2.2.0",
    "react-native-read-more-text": "^1.1.2",
    "react-native-reanimated": "^1.13.2",
    "react-native-safe-area-context": "^3.1.8",
    "react-native-screens": "^2.11.0",
    "react-native-searchable-dropdown": "^1.1.3",
    "react-native-share": "^5.1.4",
    "react-native-side-drawer": "^1.2.8",
    "react-native-side-menu": "^1.1.3",
    "react-native-simple-toast": "^1.1.3",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sound": "^0.11.0",
    "react-native-speedometer-chart": "^0.7.5",
    "react-native-splash-screen": "^3.0.6",
    "react-native-svg": "^12.1.0",
    "react-native-tab-view": "^2.15.2",
    "react-native-textinput-effects": "^0.6.1",
    "react-native-thumbnail-video": "^0.1.2",
    "react-native-tts": "^3.2.0",
    "react-native-vector-icons": "^7.1.0",
    "react-native-video": "^5.1.1",
    "react-native-video-player": "^0.10.1",
    "react-native-view-shot": "^3.1.2",
    "react-native-web": "^0.14.2",
    "react-native-webview": "^11.3.2",
    "react-otp-input": "^2.2.0",
    "react-redux": "^7.2.2",
    "react-render-html": "^0.6.0",
    "react-router-dom": "^4.3.1",
    "react-router-modal": "^2.0.0-rc3",
    "react-router-native": "^5.2.0",
    "redux": "^4.0.5",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "^0.12.0",
    "victory-native": "^35.3.1"
  },
  "devDependencies": {
    "@babel/core": "^7.11.6",
    "@babel/runtime": "^7.11.2",
    "babel-preset-react-native": "^5.0.2",
    "jest": "^26.4.2",
    "jetifier": "^1.6.7",
    "metro-react-native-babel-preset": "^0.63.0",
    "react-scripts": "^1.1.5",
    "react-test-renderer": "^16.3.1",
    "redux-devtools": "^3.7.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "homepage": "."
}

我尝试过的事情->

  1. 删除了 android 和 ios 文件夹
  2. react-native 弹出
  3. ./gradlew 干净

  1. 删除了node_modules
  2. npm 安装
  3. react-native run-android

但是没有任何效果,请帮助我,已经被困了两天了,任何线索都会有帮助。

react-native react-native-ios
4个回答
5
投票

当我弹出我的expo应用程序时,我遇到了同样的问题,如果你查看react-native-audio-recorder-player的文档,他们提到3.0.0+版本的代码库已被重写为kotlin Android 和 iOS 的 swift,

因此您需要在 build.gradle 文件中添加 kotlin 插件,

添加后,您的依赖项将类似于

希望这能解决您的问题

   dependencies {
    classpath 'com.google.gms:google-services:4.3.3',
    classpath("com.android.tools.build:gradle:3.5.3"),
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0")  //kotlin plugin

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

0
投票

将此添加到您的 android gradle 文件中

文件路径 -> 项目名称/android/build.gradle

添加以下代码

buildscript {
  ext {
      minSdkVersion = 24
      kotlinVersion = '1.5.0'
      }

  repositories {
      google()
      jcenter()
  }

  dependencies {
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
  }

0
投票

在你的 android build.gradle 文件中添加这一行

您的项目 - android/build.gradle

buildscript {
       ext {
             buildToolsVersion = "31.0.0"
             minSdkVersion = 24
             compileSdkVersion = 31
             targetSdkVersion = 31
             kotlinVersion = '1.5.0'
..............

dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
........

0
投票

检查你的java版本,我通过使用brew将mac上的java版本升级到zulu 17来解决它。

© www.soinside.com 2019 - 2024. All rights reserved.