首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >离子4:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug‘执行失败

离子4:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug‘执行失败
EN

Stack Overflow用户
提问于 2020-03-17 06:48:13
回答 4查看 3K关注 0票数 1

我在构建我的离子4应用程序时遇到了困难。每次我尝试构建android应用程序时,都会出现以下错误。

代码语言:javascript
复制
FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:   Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

* 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 19s
> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED 36 actionable tasks: 2 executed, 34 up-to-date F:\WorkSpace\Ionic Programs\Project\sujagSindhiSamiti\platforms\android\gradlew: Command failed with exit code 1 Error output: D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:   Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

* 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 19s [ERROR] An error occurred while running subprocess cordova.

        cordova.cmd build android exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information. 

我遵循了推送通知的说明:https://ionicframework.com/docs/native/fcm

我遵循了验证电话号码的说明:https://ionicframework.com/docs/native/firebase-authentication

在运行过程中添加了一个用于防火墙身份验证的插件之后,应用程序就会出现错误。

app.module.ts

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { HttpClientModule } from '@angular/common/http';
import { Device } from '@ionic-native/device/ngx';
import { CallNumber } from '@ionic-native/call-number/ngx';
import { Contacts } from '@ionic-native/contacts/ngx';
import { SocialSharing } from '@ionic-native/social-sharing/ngx';
import { File } from '@ionic-native/file/ngx';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { FilePath } from '@ionic-native/file-path/ngx';
import { FileChooser } from '@ionic-native/file-chooser/ngx';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
import { FCM } from '@ionic-native/fcm/ngx';
import { FirebaseAuthentication } from '@ionic-native/firebase-authentication/ngx';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HttpClientModule],
  providers: [
    StatusBar,
    SplashScreen,
    Device,
    CallNumber,
    Contacts,
    SocialSharing,
    File,
    FileTransfer,
    FileTransferObject,
    FileChooser,
    FilePath,
    InAppBrowser,
    FCM,
    FirebaseAuthentication,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

login.ts

代码语言:javascript
复制
import { Device } from '@ionic-native/device/ngx';
import { FCM } from '@ionic-native/fcm/ngx';
import { FirebaseAuthentication } from '@ionic-native/firebase-authentication/ngx';

constructor(private router: Router, public platform: Platform, private device: Device,private fcm: FCM, private firebaseAuthentication: FirebaseAuthentication) { 
this.platform.ready()
    .then(() => {
      this.fcm.onNotification().subscribe(data => {
        if (data.wasTapped) {
          console.log("Received in background");
        } else {
          console.log("Received in foreground");
        };
      });


      this.fcm.onTokenRefresh().subscribe(token => {
        alert(token);
      });
    })
  }

subscribeToTopic() {
    this.fcm.subscribeToTopic('enappd');
  }
  getToken() {
    this.fcm.getToken().then(token => {
      alert(token);
      this.userData.fcm_id = token;
    });
  }
  unsubscribeFromTopic() {
    this.fcm.unsubscribeFromTopic('enappd');
  }

login(){
    this.userData.imei_no = this.device.uuid;

    this.fcm.getToken().then(token => {
      alert('FCM Token: ' + token);
      this.userData.fcm_id = token;
    });

    this.firebaseAuthentication.verifyPhoneNumber("+919824592145", 30000).then((verificationID) => {
      console.log(verificationID);
      this.verificationID = verificationID;
      alert(verificationID);
    }).catch((error) => {
        console.log(error);
        alert(error);
    });
}
EN

回答 4

Stack Overflow用户

发布于 2020-07-28 05:55:36

代码语言:javascript
复制
ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter

简单地添加这些插件就可以消除任何构建错误。

票数 15
EN

Stack Overflow用户

发布于 2020-03-18 05:43:51

我也有同样的问题。这为我解决了问题。

  1. 从终端cordova clean中清除
  2. 从终端ionic cordova build android重建

删除平台并再次添加

票数 0
EN

Stack Overflow用户

发布于 2020-11-08 17:26:08

在我的离子型应用程序中,我也面临着同样的问题,在尝试了StackOverflow中最好的开发人员提出的所有建议之后,没有什么效果。然后我试了一下,它就像一种魅力

离子修复

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60717441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档