【问题标题】:Gradle build error when trying to Generate Signed Apk尝试生成签名 Apk 时出现 Gradle 构建错误
【发布时间】:2018-09-11 05:59:33
【问题描述】:

大约 34 小时前,我生成了一个签名的 apk,但现在,我无法生成一个签名的 Apk,我不知道如何解决这个问题。请帮忙

这是我的输出消息

错误:注意:有 11 个重复的类定义。 (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass) FAILURE:构建失败并出现异常。

10 秒后构建失败

这是我的 build.gradle(app)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.myapp……"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 5
        versionName "5.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$support_version"
    implementation "com.android.support:design:$support_version"
    implementation "com.android.support:support-v4:$support_version"
    implementation "com.android.support:cardview-v7:$support_version"
    implementation "com.android.support:recyclerview-v7:$support_version"
    implementation "com.google.firebase:firebase-core:$firebase_version"
    implementation "com.google.firebase:firebase-messaging:$firebase_version"
    implementation "com.google.firebase:firebase-ads:$firebase_version"
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.1'
    implementation "com.google.firebase:firebase-perf:$firebase_version"
    implementation 'io.github.yavski:fab-speed-dial:1.0.6'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.codemybrainsout.rating:ratingdialog:1.0.8'
    implementation 'com.android.billingclient:billing:1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'org.jsoup:jsoup:1.10.3'
    testImplementation 'junit:junit:4.12'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'

apply plugin: 'kotlin-android-extensions'

这是我的 build.gradle(project)

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

buildscript {
    ext.kotlin_version = '1.2.10'
    ext.support_version = '26.1.0'
    ext.firebase_version = '12.0.1'
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'io.fabric.tools:gradle:1.25.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

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

【问题讨论】:

    标签: android gradle android-gradle-plugin proguard


    【解决方案1】:

    这是一个 lintValidRelease 问题。 您需要在 Gradle 文件中添加 lintOptions。

    android {
    ..
         lintOptions {
    
            checkReleaseBuilds false
    
        }
    }
    

    【讨论】:

    • 谢谢!那会起作用,但我所做的是在生成签名的 Apk 时连接到互联网,它本身就发挥了作用
    • 添加lintOptions 有效,但这似乎是一种解决方法。根本原因是什么?我已连接到互联网,但它没有帮助。
    • 我也想找到这个的根本原因。突然我的 CircleCi 开始向我抛出这个错误Execution failed for task 'app:lintVitalRelease'. > Could not resolve all files for configuration 'app:lintClassPath'. > Could not find lint-checks.jar (com.android.tools.lint:lint-checks:26.1.2). Searched in the following locations: https://jcenter.bintray.com/com/android/tools/lint/lint-checks/26.1.2/lint-checks-26.1.2.jar
    • 禁用防火墙有时可能对您有所帮助
    【解决方案2】:

    对我来说,问题是由于allproject 部分中缺少存储库:

    buildscript {
        repositories {
            mavenCentral()
            google()
            jcenter()
        }
    }
    
    allprojects {
        ...
        repositories {
            mavenCentral()
            google()
            jcenter()
        }
    }
    

    在我添加google()jcenter() 之后,项目现在构建成功

    【讨论】:

    • 对我来说似乎没有什么不同,至少在 build.gradle 中没有比“app”目录高一级。
    猜你喜欢
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2021-08-29
    相关资源
    最近更新 更多