How to add Android support to my Ionic app project

2019-07-20 06:07发布

问题:

I have created an Ionic app project. I want to add Android support to my app. For that I used "ionic platform add Android. But my system shows some errors. I am using a windows machine. The errors showing in cmd is

    Adding android project...

Running command: cmd "/s /c "C:\Users\SYSTEM-03\.cordova\lib\npm_cache\cordova-android\6.0.0\package\bin\create.bat E:\workspace\appstore\demoapp\platforms\android com.ionicframework.demoapp722446 demoapp --cli""

C:\Users\SYSTEM-03\.cordova\lib\npm_cache\cordova-android\6.0.0\package\bin\templates\cordova\lib\AndroidStudio.js:16
    for(file of eclipseFiles) {
             ^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\Users\SYSTEM-03\.cordova\lib\npm_cache\cordova-android\6.0.0\package\bin\templates\cordova\lib\AndroidProject.js:24:21)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

回答1:

You need to install java with required version and Android studio. Set the path in the environment variables for both java and android studio.

Follow these steps

Requirements

In order to install ionic framework, we should have the following requirements. It supports iOS 6+, Android 4.0+. Node.js Apache Cordova Ionic Git Java JDK Apache Ant Android Studio Google Chrome Canary (Optional)

Steps in Windows OS Download and install Node.js from this. (Here node.js is an executable file)

Install Cordova Use the below command to install cordova. (npm is a node.js related command)

C:\ npm install -g cordova

Install iconic

C:\ npm install -g ionic

Install Git Download and install Git from this. Choose “Run Git from the Windows Command Prompt” option while installing. Git will be used when we want to install cordova plugins from github (.git files).

Install JDK, Apache Ant, Android Studio Install most recent Java JDK (not just JRE) from this Create an environmental variable for JAVA_HOME pointing to java JDK root folder.

C:\ set JAVA_HOME=“C:\Program Files\Java\jdk7”

Add JDK’s bin to the PATH environmental variable

C:\ set PATH=%PATH%;“C:\Program Files\Java\jdk7\bin”

Download Apache Ant from this. Extract it to the C:\ directory Add Ant’s bin to the PATH environmental variable

C:\ set PATH=%PATH%;“C:\apache-ant-1.9.2\bin”

Download Android Studio from this. Install Android Studio Open “Android SDK Manager” from Android Studio “Configure” option Select following packages. Android SDK Tools Android SDK Platform-tools Android SDK Build-tools for Revision 20 & 19 Android 6.0 (API 23) Android 4.4W.2 (API 20) Android 4.4.2 (API 19) Android Support Library (From Extras) Click on “Install Packages” and accept license for all packages. Cordova requires the ANDROID_HOME environmental variable to set.

C:\ set ANDROID_HOME=“C:\android\sdk”

Update PATH variable to include tools/ and platform-tools/ folder in that folder.

C:\ set PATH=%PATH%;%ANDROID_HOME%\tools
        C:\ set PATH=%PATH%;%ANDROID_HOME%\platform-tools

Create Ionic project We can create Cordova-Ionic project somewhere on the computer. C:\ ionic start [blank/tabs/sidemenu/maps] C:\ cd

Ionic command line features: a. start: c:> ionic start myproj blank Creates ionic project in the in which directory you have run this command.

b. serve: c:\myproj> ionic serve Starts local development server to run the project.

c. platform: c:\myproj> ionic platform add android Configure cordova for desired platform android or ios.

d. build: c:\myproj> ionic build android Build executes a local build for the platform which we specify. This creates CordovaApp-debug.apk file in c:\myproj\platforms\android\ant-build location.

e. emulate: c:\myproj> ionic emulate android Starts the app in specified platform

f. run: c:\myproj> ionic run android Deploys and runs the app on the actual mobile device

g. Install IOS emulator test ios build in windows machine c:\ npm install -g ios-sim