Wednesday 11 November 2015

How to deploy .apk (Android)

Build.
1. gulp build
2. phonegap build android

Deploy with signed.

1. Open Android Studio.
2. Open Angular js project folder >> platforms >> android
3. Follow pics below.
















Deploy to apk fails when unsigned.


http://stackoverflow.com/questions/20402818/build-android-release-apk-on-phonegap-3-x-cli/22979830#22979830



How to install Android emulator on MAC

Follow this link to install Android SDK
http://www.petefreitag.com/item/763.cfm


Change $PATH to run sdk anywhere
http://stackoverflow.com/questions/5526470/trying-to-add-adb-to-path-variable-osx

http://hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac


When I do below, I got error complaining
phone gap build android

[Error: Please install Android target: "android-22".

I found a solution here.
http://stackoverflow.com/questions/29396252/cordova-error-please-install-android-target-android-21

You should change target in 3 places.

Then phone gap build android starts working.

Sunday 8 November 2015

phonegap build android - error

After doing Angular js coding for a while, suddenly, the below line didn't work.
phonegap build android

How I bang my head on wall

The build command returned error. iOS was working fine. But phonegap run android returned broken pages and WEB API returned nothing.


I removed android platform and added again. Didn't help.
I installed phonegap again with latest. Didn't help


I started deleting entire www folder. Because I thought 'gulp build' makes whole www again. I was wrong!!!


The icon in res\redrawable-hd folder generated and deleted.

At one stage, I thought the above was this error in below link. But it wasn't.
http://javalearnersproblems.blogspot.com.au/2011/11/androidmanifestxml-has-error-no.html



Then I found I am missing folders and files under www. See how js folder only is regenerated when you run 'gulp build'.

The error below is irrelevant. I don't know what it means. Maybe my index.html had problem.

I have copied some of my head banging cmd dump in this HTML file. Look at the red color lines.

Solution

I found that after 'phonegap build android', actually the error message shows 'FAIL' at first time, complaining about 'administrator's Macbook's index.html'. What the xxx?? I found that that strange file exists in www folder. It must be generated while I was doing some copy/paste.

1. I deleted that file.
2. gulp build
3. phonegap build android
=> platforms, androidManifest.xml etc is generated. I guess. Emulator is not refreshing without build.
4. phonegap run android.

All worked good!
See the 'Other' text shows on top? That's from web api!!!


After a few days later ...

When I worked well in iOS for a while and came back to windows for Android test, it started showing error again when I 'phonegap build android'. The error message was ..

C:\Users\matthew.oh\Dropbox\my-app\angularui\platforms\android\AndroidManifest.xml:27:9 Error:
        Element service#com.adobe.phonegap.push.GCMIntentService at AndroidManifest.xml:27:9 duplicated with element declared at AndroidManifest.xml:19:9
 FAILED

It complained about GCM push something.
This is what I did to fix it.

1. phonegap platforms remove android
2. phonegap platforms add android
3. phonegap plugin remove phonegap-plugin-push
4. phonegap plugin add phonegap-plugin-push
5. gulp build
6. phonegap build android

Then it was ok.