React-native项目构建失败:找不到com.android.tools.lint:lint-gradle:26.1.0

时间:2018-04-09 14:07:28

标签: android react-native gradle

我在尝试生成apk的新版本时遇到了一些问题。 (但是应用程序在使用react-native run-android

的调试中正常运行

首先,我有输出消息:

  

任务:react-native-maps:compileReleaseJavaWithJavac注意:一些输入   文件使用或覆盖已弃用的API。注意:重新编译   -Xlint:弃用细节。注意:某些输入文件使用未经检查或不安全的操作。注意:使用-Xlint重新编译:未选中   的信息。

     

失败:构建因异常而失败。

     

>出了什么问题:无法解析配置的所有文件':react-native-maps:lintClassPath'。

     
    

找不到com.android.tools.lint:lint-gradle:26.1.0。在以下位置搜索:           文件:/ C:/Users/kev_w/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom           文件:/ C:/Users/kev_w/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar           文件:/ C:/Users/kev_w/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom           文件:/ C:/Users/kev_w/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar           文件:/ C:/Users/kev_w/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom           文件:/ C:/Users/kev_w/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar           文件:/ C:/Users/kev_w/.m2/repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom           文件:/ C:/Users/kev_w/.m2/repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar           https://jcenter.bintray.com/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom           https://jcenter.bintray.com/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar           文件:/ C:/Users/kev_w/Desktop/Ulabs/appreactnative/testApp/node_modules/react-native/android/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0。 POM           文件:/ C:/Users/kev_w/Desktop/Ulabs/appreactnative/testApp/node_modules/react-native/android/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0。罐     要求:           project:react-native-maps *

  

1.我做了什么来解决这个问题: 在我的 android / build.gradle >>中添加google() allprojects {...}

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

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

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

添加此内容后,构建成功,但是当我打开它时,我的apk会立即崩溃...

正如我在开始时所说的,在添加google()之前,我的项目在使用react-native run-android的调试中正常运行。 但是现在,apk和调试项目都不起作用。

没有任何记录就崩溃了。

然后我尝试在我的android / app / build.gradle中运行apk版本删除google()并添加lintOptions

android {
 (...)
    lintOptions {

        checkReleaseBuilds false
        abortOnError false
    }
}

在我的android/app/build.gradle中,以避免lint-gradle错误>它没有用。

这是我的整个android/app/build.gradle

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.testapp"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

    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
            }
        }
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }

    android {
        lintOptions {
            abortOnError false
            checkReleaseBuilds false
        }
    }

    buildTypes {
        release {
            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:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            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 {
    compile project(':react-native-linear-gradient')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile project(':react-native-linear-gradient')
    compile project(':react-native-device-info')
    /*implementation project('react-native-maps')*/
    implementation(project(':react-native-maps')){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:11.0.4'
    implementation 'com.google.android.gms:play-services-maps:11.0.4'
}

// 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'
}

我花了好几个小时试图在网上找到解决方案,但没有什么对我有用。要么我的run-android工作和应用程序没有崩溃,但无法构建任何apk,或者我可以构建它但它立即崩溃当我运行它(apk或运行android)...

如果有人能保存我的心理健康,请^^ ...

3 个答案:

答案 0 :(得分:10)

您是否曾在jcenter()之前尝试使用google()?它对我有用:



buildscript {
    repositories {
        google()
        jcenter()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        // NOTE: Do not place your application dependencies here;
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}




答案 1 :(得分:0)

我们遇到了完全相同的问题,并找到了解决问题的两种方法。

第一个:将Gradle评级降至版本2.2.3

更好的一个:对我来说问题是由react-native-map创建的,要解决它你必须从

编辑app / build.gradle
implementation 'com.google.android.gms:play-services-base:11.0.4'
implementation 'com.google.android.gms:play-services-maps:11.0.4'

为:

implementation "com.google.android.gms:play-services-base:+"
implementation "com.google.android.gms:play-services-maps:+"

答案 2 :(得分:-1)

以下代码对我有用。

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

 buildscript {
repositories {
    google()
    jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'

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

allprojects {
repositories {
    google()
    jcenter()
}
}

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