我在构建ionic 4应用程序时遇到了麻烦。每次我尝试构建android应用时,都会出现以下错误。
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
在运行应用程序时添加用于Firebase身份验证的插件后,会发生错误。
app.module.ts
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
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);
});
}
答案 0 :(得分:8)
Candle::new()
只需添加这些插件即可消除所有构建错误。
答案 1 :(得分:0)
我有同样的问题。这为我解决了。
cordova clean
的ionic cordova build android
重建[或
删除平台并再次添加
答案 2 :(得分:0)
我在离子应用程序中遇到了同样的问题,在尝试了StackOverflow中最好的开发人员建议的一切后,没有任何效果。然后我尝试了一下,它就像一个魅力
离子修复
答案 3 :(得分:0)
提议的解决方案 here 对我有用。
移除安卓平台
ionic cordova platform rm android
删除与支持、gradle 和/或 firebase 版本控制相关的插件。就我而言,这有点奇怪,我删除了本地通知插件。
添加 androidX 插件
cordova plugin add cordova-plugin-androidx
cordova plugin add cordova-plugin-androidx-adapter