Ionic cordova build android –prod –release fails w

2019-01-29 10:50发布

问题:

I’m working with Ionic 3. When I try cordova build android --prod --release, a build is done, but the signed APK is showing white screen after splash. When I try ionic cordova build android --prod --release, it is showing the following error.

Main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

app.module.ts

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
import { AppRate } from '@ionic-native/app-rate';
import { PopoverPage } from '../pages/popover/popover';

import { TabsPage } from '../pages/tabs/tabs';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { LoginPage } from '../pages/login/login';

import { PostService } from './app.postservice';
import { UrlService } from './app.service';
import { GetService } from './app.getservice';
import { AppVersion } from '@ionic-native/app-version';
import { SlidersPage } from '../pages/sliders/sliders';


@NgModule({
  declarations: [
    MyApp,
    TabsPage,
    LoginPage,
    SlidersPage
  ],
  imports: [
    BrowserModule,
    HttpModule,
     IonicModule.forRoot(MyApp,{
       tabsHideOnSubPages: true
     })
    
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    LoginPage,
    SlidersPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    AppVersion,
    AppRate,
    
    BarcodeScanner,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    {provide: PostService, useClass: PostService},
    {provide: UrlService, useClass: UrlService},
    {provide: GetService, useClass: GetService},
  ],

})
export class AppModule {}

Ionic info gives

cli packages: (C:\Users\akrra\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.2
Cordova Platforms  : android 6.3.0 windows 5.0.0
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v9.2.0
npm  : 5.5.1
OS   : Windows 10

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : legacy

回答1:

Ionic Cli seems to be having issues with reporting the correct error when running with --prod option. It is throwing "Can't resolve './app.module.ngfactory'" instead of the correct error message.

It is being tracked here and here.

A developer with Ionic Dan Bucholtz suggested a workaround to retrieve the actual error message here.

In the meantime, to see the errors in your application and fix them, try running:

./node_modules/.bin/ngc

You can run the above command to figure out what the real issue in your app is.