cordova run android executes fine. But Android 4.1

2019-01-10 20:51发布

I'm starting to develop and android app using Cordova 5.0.0 (cordova -v prints 5.0.0), and testing it on a Moto Razr D1 with Android 4.1.2. Under Windows 7, btw.

cordova build 

and manually copying the platforms/android/build/output/apk/android-degug.apk to the SD and installing works fine.

cordova emulate android 

runs fine on emulator with android version >4.1.2

cordova run android 

builds successfully, says using apk platforms/android/build/output/apk/android-debugger.apk, which seems ok, installing app, launching and LAUNCH SUCCESS. however as you can see in this screenshot

Razr Screenshot

This "WALLPAPER/MANAGE/SETTINGS" thing happens, and that's it.

If I execute:

cordova emulate android

On an emulator with Android 4.1.2 Jelly, an equal output

BUILD SUCCESSFUL

Total time: 6.352 secs
Built the following apk(s):
    C:\android\Some\platforms\android\build\outputs\apk\android-debug.apk
Installing app on emulator...
Using apk: C:\android\Some\platforms\android\build\outputs\apk\android-debug.apk
Launching application...
LAUNCH SUCCESS

same "WALLPAPAER/MANAGE/SETTINGS", here's another screenshot Emulator Screenshot

Any ideas how to solve this issue? Thanks in advance...

PS: If I've installed the apk previously, the Razr will startup the old version, instead of the WALLPAPER/MANAGE/SETTINGS thing. So I have to uninstall it before trying to run the cordova run commands.

7条回答
甜甜的少女心
2楼-- · 2019-01-10 21:15

The solution is: edit emulator.js under platforms\android\cordova\lib

Go to line 311 and comment out the line

// return exec('adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path + '"', os.tmpdir())

and paste new line

return exec('adb -s ' + resolvedTarget.target + ' install -r  "' + apk_path + '"', os.tmpdir())

it works.

查看更多
仙女界的扛把子
3楼-- · 2019-01-10 21:15

Try to use simple -

cordova run anroid

If there is no conencted device it will show "No target specified and no devices found, deploying to emulator" and will launch the emulator.

查看更多
对你真心纯属浪费
4楼-- · 2019-01-10 21:28

Changing the code in device.js and emulator.js didn't work for me (and in fact introduced an error where cordova build android wouldn't work anymore). My problem was completely different: I had two <application>s in my AndroidManifest.xml which is apparently not allowed.

Somewhere along the line I had added <application android:debuggable="true" /> to my AndroidManifest.xml. However, that file already had an "application" element that looked like this:

<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">

So I added the "debuggable" line to the existing <application> (and removed the second <application>) like so:

<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">

After that I rebuilt using cordova build android, ran it successfully on my device with cordova run android, and then clapped my hands and scared my dog.

HOWEVER, even if this isn't your issue, here's how I discovered the problem: I followed the instructions in jojo's answer and ran adb logcat with my device connected. That terminal tab immediately filled up with interminable crap.

Then I opened a new terminal window that I could view at the same time, I took note of the latest timestamp in the logcat output, and I ran cordova run android. The screen filled up with more crap, and then once things calmed down I scrolled back up to my starting time and reviewed it line by line. Eventually I found my culprit:

PackageParser: <manifest> has more than one <application>

Hope this helps!

查看更多
时光不老,我们不散
5楼-- · 2019-01-10 21:29

I met the same problem (Cordova "hello world" app won't display) and found a way to pass through it (but I don't really understand the underlying causes).

Problem seemed to occur when installing the apk. On Cordova 5.0.0, adb commands to install the apk can be found at line 101 of file platforms\android\cordova\lib\device.js (and at line 311 of platforms\android\cordova\lib\emulator.js for cordova emulate android):

adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path + '"

Current command returns to me: "Error: unknown option -d"!

If you simply delete the "-d" option, applications run normally with cordova run android.

EDIT

The -d is supposed to come directly after adb (as in --device) instead of after install. So you can just move it there instead of removing it.

Plus, here is the opened issue on apache cordova issue tracker

查看更多
姐就是有狂的资本
6楼-- · 2019-01-10 21:31

for me this trick worked perfectly by removing the -d

but i had to install the apk manullay for the first time by transferring to phone and then i was able to run the app directly using ionic run android

hope this helps someone

查看更多
Lonely孤独者°
7楼-- · 2019-01-10 21:32

For those using Cordova 6.1.1 and having similar problem of not opening/installing the app, what worked for me was to run ionic emulate android once to open the android emulator with a home screen. Then, in another terminal window run again ionic emulate android which installed the application on the already opened emulator and everything worked normally.

Found similar problem in here: https://forum.ionicframework.com/t/ionic-serve-works-correctly-ionic-emulate-android-just-displays-android-emulator-home-screen/53524/6

查看更多
登录 后发表回答