简体   繁体   English

从angular2新鲜的cordova构建在Android上构建白色屏幕

[英]fresh cordova build from angular2 build white screen on android

I copied my angular2 folder to a new folder, ran npm I etc. in Angular it runs fine. 我将我的angular2文件夹复制到一个新文件夹,然后在Angular中运行npm I等,它运行正常。

I created a Cordova folder in my folder with 我在文件夹中创建了一个Cordova文件夹

cordova create cordova be.volckaertachiel.be "volckaertAchiel"

then: 然后:

cd cordova
cordova platform add browser
cordova run browser
rm -r www
cd ..

build it in the corodova folder with: 使用以下命令将其构建在corodova文件夹中:

 ng build --target=production --environment=prod --output-path cordova/www/

And then ran it in the browser with Cordova run browser 然后使用Cordova run browser在浏览器中运行它

After I changed my backend(node.js API) to accept port 8000 it ran like it was running in angular2 在将后端(node.js API)更改为接受端口8000它的运行就像在angular2中运行一样

After this Cordova platform add android and then Cordova build android 在此Cordova platform add android ,然后在Cordova build android

it launched the Android SDK, it launched the app, but it has a white screen... 它启动了Android SDK,启动了该应用程序,但屏幕为白色...

My issue in short : I build my web with Cordova -> runs fine, on android I just get a white screen. 简而言之,我的问题是 :我用Cordova建立了我的网站->运行良好,在android上我只得到了一个白屏。

Updated Issue : compiled js files aren't found in android 更新的问题 :android中找不到编译的js文件

通过从此<base href="/">设置为此<base href="./">来解决找不到文件的问题,在此处也进行了说明: https : //github.com/electron/electron/issues / 1769

There are two possibilities for this type of behavior: 对于这种类型的行为,有两种可能性:

1. Splash screen misconfiguration 1.启动画面配置错误

Check your config.xml and verify that you have: 检查您的config.xml并确认您具有:

  • Configured your splash screen to hide automatically 将启动屏幕配置为自动隐藏
  • Specified valid splash screen images. 指定了有效的初始屏幕图像。

Here's a sample config for Android that will hide the splash screen after 10 seconds: 这是Android的示例配置,将在10秒后隐藏启动屏幕:

<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="10000" />
<platform name="android">
    <preference name="android-minSdkVersion" value="16" />
    <preference name="android-targetSdkVersion" value="22" />
    <allow-intent href="market:*" />
    <icon density="ldpi" src="res/icons/android/ldpi.png" />
    <icon density="mdpi" src="res/icons/android/mdpi.png" />
    <icon density="hdpi" src="res/icons/android/hdpi.png" />
    <icon density="xhdpi" src="res/icons/android/xhdpi.png" />
    <icon density="xxhdpi" src="res/icons/android/xxhdpi.png" />
    <splash density="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />
    <splash density="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />
    <splash density="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />
    <splash density="port-xhdpi" src="res/screen/android/splash-port-xhdpi.png" />
</platform>

2. Index page bug 2.索引页错误

Check your index.html stored in www . 检查存储在wwwindex.html Is it missing? 它丢失了吗? Is it empty? 是空的吗? Does it load a white page when you open it in a browser? 在浏览器中打开白页时是否加载白页?

If the index.html file is present and loading properly in a web browser then you will need to inspect the app while it's running on your Android device. 如果存在index.html文件并已在网络浏览器中正确加载,那么您需要在Android设备上运行该应用程序时对其进行检查。 It's likely throwing a JavaScript error during page load that's preventing anything from being displayed. 在页面加载期间可能会引发JavaScript错误,从而无法显示任何内容。 To do so, follow these steps: 这样做,请按照下列步骤操作:

  • Enable developer mode debugging on your Android. 在Android上启用开发人员模式调试。
  • Connect your device to your computer via USB. 通过USB将设备连接到计算机。
  • Compile the app for debug and run it on your Android device: cordova run android --debug --target=YOURDEVICEIDHERE 编译应用程序以进行调试,然后在您的Android设备上运行它: cordova run android --debug --target=YOURDEVICEIDHERE
  • Open up Chrome on your desktop and navigate to chrome://inspect 在您的桌面上打开Chrome并导航到chrome://inspect

You can live inspect your app just like you would a regular web page. 您可以像常规网页一样实时检查您的应用程序。 Hitting the refresh button will re-run the initial load and allow you to log any errors. 点击刷新按钮将重新运行初始加载,并允许您记录任何错误。

This is solution may be application if you want are running on android 8.0 emulator/device with angular 8. 如果您要在角度为8的android 8.0仿真器/设备上运行,则此解决方案可能是应用程序。

For android 8.0 emulators, it does not support ES2015 which is ES6. 对于android 8.0模拟器,它不支持ES6,即ES6。

  • Go to your angular project 去你的角度项目
  • Then edit the target to "es5" in tsconfig.json 然后在tsconfig.json中将目标编辑为“ es5”

Just in case someone else get here with this problem without lucky: in my case, i had to change the script in index.html, removing the scripts wicht type was "module" and removing the attribute "nomodule". 以防万一有人碰到这个问题而没有运气:就我而言,我不得不更改index.html中的脚本,删除脚本类型为“ module”的脚本,并删除属性“ nomodule”。

In other words, i changed from this: 换句话说,我改变了:

<script src="runtime-es2015.js" type="module"></script>
<script src="polyfills-es2015.js" type="module"></script>
<script src="main-es2015.js" type="module"></script>
<script src="runtime-es5.js" nomodule></script>
<script src="polyfills-es5.js" nomodule></script>
<script src="main-es5.js" nomodule></script>
<script src="scripts.js"></script>

To this: 对此:

<script src="runtime-es5.js"></script>
<script src="polyfills-es5.js"></script>
<script src="main-es5.js"></script>
<script src="scripts.js"></script>

It looks like it has something to do with what mingliang94 said, but my emulator is android 9. 看来与mingliang94所说的有关,但我的模拟器是android 9。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM