【问题标题】:Error while setting up Instant Apps设置免安装应用时出错
【发布时间】:2018-02-04 12:24:48
【问题描述】:

我正在尝试为我的应用实现 Android 即时应用支持,并且我已按照本教程进行操作:

http://androidkt.com/instant-app/

一切都很顺利,我已经成功完成了教程。

但是,我遇到了这个错误:

错误:失败:构建失败并出现异常。

  • 出了什么问题:任务 ':appapk:preDebugBuild' 执行失败。 > Android 依赖 'com.android.support:support-v4' 有不同 编译 (25.2.0) 和运行时 (27.0.1) 类路径的版本。你 应该通过 DependencyResolution 手动设置相同的版本

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

1 秒内构建失败

我的项目针对的是最新版本的 Android (Android 8.1 API 27),因此,所有版本都应为 27 及以上。

我认为这个错误是因为 com.android.support:support-v4version 25.2.0 但是当我搜索我的整个项目时,我找不到 @987654327 @ 或 25.2.0 的任何文件。

如果需要,这是我的 gradle 文件:

build.gradle(项目):

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

buildscript {
    repositories {

        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.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.1'
    }
}

allprojects {
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
            maven { url 'https://jitpack.io' }
        }



        jcenter()
        google()
    }
}

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

build.gradle(模块:app-base):

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    baseFeature = true
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 27
        multiDexEnabled true
        versionCode 3
        versionName "2.0.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    implementation 'com.android.support:support-v4:27.0.1'
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //compile 'android-support-v7-appcompat:25.0.1'

    implementation 'com.github.HITGIF:TextFieldBoxes:1.3.8'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.google.firebase:firebase-crash:11.8.0'
    implementation 'com.google.firebase:firebase-ads:11.8.0'
    implementation 'com.google.android.gms:play-services-ads:11.8.0'
    implementation 'com.google.firebase:firebase-core:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.android.gms:play-services:11.8.0'
    implementation 'com.android.support:design:24.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:cardview-v7:24.2.1'
    implementation 'com.android.support:customtabs:27.0.2'
    testImplementation 'junit:junit:4.12'
}


apply plugin: 'com.google.gms.google-services'

build.gradle(模块:appapk):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26



    defaultConfig {
        applicationId "tr.k12.evrim.evrimnews.app"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':app-base')
    implementation 'com.android.support:appcompat-v7:27.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

build.gradle(模块:instantapp):

    apply plugin: 'com.android.instantapp'

android {
    buildToolsVersion "26.0.2"
}

dependencies {
    implementation project(':app-base')
}

【问题讨论】:

  • 运行 gradlew appapk:dependencies 以显示所有传递依赖项.....这应该突出显示该版本中的内容
  • @JohnO'Reilly 这可能是一个愚蠢的问题,但我该如何运行呢?终端? :(
  • 是的,您可以在项目根文件夹的终端中运行(这里有更多背景知识 - developer.android.com/studio/build/building-cmdline.html
  • @JohnO'Reilly 终端输出:gist.github.com/TurboProgramming/…
  • @JohnO'Reilly 有什么解决方案吗?

标签: android gradle android-gradle-plugin android-instant-apps


【解决方案1】:

参考google issue Tracker,我们能够使用与build.gradle 文件中相同的设置在应用程序中重现该问题。

将基础中的 com.android.support:support-v4 依赖项从 implementation 更改为 api 时,应用程序可以成功编译 更新 com.android.support:appcompat-v7:27.0.127.0.2

实现api的区别在于

implementation 不会将依赖项暴露给其他依赖它的模块,包括需要同步到更高版本(在本例中为 25.xx 到 27)的库.

api 依赖项将暴露给库的所有使用者。

【讨论】:

    猜你喜欢
    • 2021-09-14
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    相关资源
    最近更新 更多