AndroidX突然导致NativeScript的构建失败

时间:2019-06-18 17:33:42

标签: android nativescript

突然之间,我的依存关系没有变化,我现在遇到以下错误:

Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:18:2-31:16 to override.

我尝试应用该建议(以及相关的命名空间XML属性),但不幸的是,这会产生一条multiple errors, see logs的消息,但我不知道日志在哪里。

我已经阅读并阅读了此书,并且我理解尝试同时拥有AndroidX和现已弃用的支持库是一个问题。但是,在此突然停止构建之前,我没有更改任何依赖关系-仅清除了平台以强制进行完全重建。

我不知道哪个插件有冲突,我也知道Jetifier应该解决这个问题,除了NativeScript似乎不让我能够以任何持久的方式修改gradle.properties的能力(知道)和当前最新版本的NativeScript(这令人困惑,因为NativeScript5.4.1TNS core modules5.4.2,并且该平台已添加到我的package.json中似乎是5.4.0)似乎没有利用Jetifier,并且基于NPM的最新AndroidX构建似乎已经过时了。

那么,如何恢复我的应用程序并立即运行?救命!

5 个答案:

答案 0 :(得分:5)

因此,我通过将支持依赖项移至before-plugins.gradle(现在看起来像这样)来解决此问题:

project.ext {
  googlePlayServicesVersion = "15.0.0"
}

dependencies {
  compile 'com.squareup.picasso:picasso:2.71828'
  def googlePlayServicesVersion = project.googlePlayServicesVersion
  compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
  compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
  def supportVer = "28.0.0"
  compile "com.android.support:support-v4:$supportVer"
  compile "com.android.support:appcompat-v7:$supportVer"
  compile "com.android.support:design:$supportVer"
}

好吧,这是我的app.gradle

android {
  defaultConfig {
    // Fix for: The number of method references in a .dex file cannot exceed 64K.
    // (see: https://developer.android.com/tools/building/multidex.html)
    multiDexEnabled true
    minSdkVersion 17
    generatedDensities = []
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

def settingsGradlePath

if(project.hasProperty("appResourcesPath")){
    settingsGradlePath = "$project.appResourcesPath/Android/settings.gradle";
} else {
    settingsGradlePath = "$rootDir/../../app/App_Resources/Android/settings.gradle";
}

def settingsGradleFile = new File(settingsGradlePath);

if(settingsGradleFile.exists())
{
    apply from: settingsGradleFile;
}

答案 1 :(得分:0)

强制以下依赖项对我有用。

dependencies {

    compile 'com.google.android.gms:play-services-analytics:16.0.4'

    implementation('com.google.android.gms:play-services-analytics:16.0.6'){

    force = true

  }

  implementation('com.google.android.gms:play-services-base:16.1.0'){

    force = true

  }
}

答案 2 :(得分:0)

我通过查看./gradlew app:dependencies来解决此问题,并修复了所有似乎使用更新的依赖项(将androidx使用到以前的版本)的软件包。

enter image description here

所以您可以在这里看到tagmanager解析为17,因为依赖项使用了'+',所以我将其固定为16.0.8

implementation (project(':react-native-device-info')) {
    exclude group: 'com.google.android.gms', module: 'play-services-gcm'
}

implementation (project(':react-native-google-analytics-bridge')){
    exclude group: 'com.google.android.gms', module: 'play-services-analytics'
    exclude group: 'com.google.android.gms', module: 'play-services-tagmanager-v4-impl'
}
implementation (project(':react-native-admob')) {
    exclude group: 'com.google.android.gms', module: 'play-services-ads'
}

implementation ('com.google.android.gms:play-services-gcm:16.1.0') {
    force = true
}

implementation ('com.google.android.gms:play-services-ads:17.2.0') {
    force = true
}

implementation ('com.google.android.gms:play-services-analytics:16.0.8') {
    force = true
}

implementation ('com.google.android.gms:play-services-tagmanager-v4-impl:16.0.8') {
    force = true
}

答案 3 :(得分:0)

我仅将GooglePlayservices更新为15.0.0,并将其添加到<application>中的AndroidManifest中。

 <application>
     ...
              <uses-library android:name="org.apache.http.legacy" 
               android:required="false"/>
     ...            

    <application/>

答案 4 :(得分:0)

出现相同的错误,请检查库版本,对我来说,Firebase是问题所在。

before-plugins.gradle

project.ext {
    googlePlayServicesVersion = "15.0.1"
    googleFirebaseServicesVersion = "18.0.0"
}

dependencies {

    def googlePlayServicesVersion = project.googlePlayServicesVersion
    compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
    compile "com.google.firebase:firebase-messaging:$googleFirebaseServicesVersion"
}