【问题标题】:Error when build released APK with flutter in android studio在 android studio 中使用颤振构建发布的 APK 时出错
【发布时间】:2019-03-23 13:44:11
【问题描述】:

我可以毫无问题地构建调试 apk,并且我在三个移动设备上尝试我的应用程序时没有任何错误,但是当我尝试构建已发布的 apk 时,我遇到了这个错误:

D:\mis>flutter build apk
Initializing gradle...                                           1.0s
Resolving dependencies...                                        4.5s
Gradle task 'assembleRelease'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:debugAndroidTestRuntimeClasspath'.
   > Could not resolve com.android.support:support-annotations:25.3.1.
     Required by:
         project :app
      > Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints:
           Dependency path 'android:app:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support.test:monitor:1.0.2' --> 'com.android.support:support-annota
tions:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.android.support.test.espresso:espresso-core:3.0.2' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support
:support-annotations:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-compat:25.3.1' --> 'com.android.support:support-annotations:25.3.
1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-media-compat:25.3.1' --> 'com.android.support:support-annotations
:25.3.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-core-utils:25.3.1' --> 'com.android.support:support-annotations:2
5.3.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-core-ui:25.3.1' --> 'com.android.support:support-annotations:25.3
.1'
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1

   > Could not resolve com.android.support:support-annotations:27.1.1.
     Required by:
         project :app > com.android.support.test:runner:1.0.2
         project :app > com.android.support.test:runner:1.0.2 > com.android.support.test:monitor:1.0.2
      > Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints:
           Dependency path 'android:app:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support.test:monitor:1.0.2' --> 'com.android.support:support-annota
tions:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.android.support.test.espresso:espresso-core:3.0.2' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support
:support-annotations:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-compat:25.3.1' --> 'com.android.support:support-annotations:25.3.
1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-media-compat:25.3.1' --> 'com.android.support:support-annotations
:25.3.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-core-utils:25.3.1' --> 'com.android.support:support-annotations:2
5.3.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-core-ui:25.3.1' --> 'com.android.support:support-annotations:25.3
.1'
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1

   > Could not resolve com.android.support:support-annotations:25.3.1.
     Required by:
         project :app > com.android.support:support-compat:25.3.1
         project :app > com.android.support:support-media-compat:25.3.1
         project :app > com.android.support:support-core-utils:25.3.1
         project :app > com.android.support:support-core-ui:25.3.1
      > Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints:
           Dependency path 'android:app:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support.test:monitor:1.0.2' --> 'com.android.support:support-annota
tions:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.android.support.test.espresso:espresso-core:3.0.2' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support
:support-annotations:27.1.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-compat:25.3.1' --> 'com.android.support:support-annotations:25.3.
1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-media-compat:25.3.1' --> 'com.android.support:support-annotations
:25.3.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-core-utils:25.3.1' --> 'com.android.support:support-annotations:2
5.3.1'
           Dependency path 'android:app:unspecified' --> 'com.alveliu.flutterfullpdfviewer:flutter_full_pdf_viewer:1.0.0' --> 'com.github.barteksc:android-pdf-viewer:2.8.2' --> 'com
.github.barteksc:pdfium-android:1.7.1' --> 'com.android.support:support-v4:25.3.1' --> 'com.android.support:support-core-ui:25.3.1' --> 'com.android.support:support-annotations:25.3
.1'
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1
           Constraint path 'android:app:unspecified' --> 'com.android.support:support-annotations' strictly '25.3.1' because of the following reason: debugRuntimeClasspath uses vers
ion 25.3.1


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
 6.4s
Gradle task assembleRelease failed with exit code 1

我下载了一个新的 Gradle,但还是同样的问题?

这是我的 build.gradle 文件:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}


android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.mis"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

   signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['storePassword']
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
            useProguard true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我不知道这个问题出自哪里?以及如何尝试解决它?它来自 Gradle?还是什么?

【问题讨论】:

    标签: gradle flutter


    【解决方案1】:

    添加

    lintOptions {
            disable 'InvalidPackage'
            checkReleaseBuilds false
    }
    

    android/app/build.gradle

    【讨论】:

    • 它需要在 android 部分内,而不是在根目录下。恕我直言,您应该在回复中提及这一点。
    猜你喜欢
    • 2022-01-01
    • 2021-07-12
    • 2020-12-30
    • 2022-10-25
    • 1970-01-01
    • 2020-08-23
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多