Maybe it can help you on build error with ionic/cordova error with android platform on windows
After install ant/ionic with :
%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\build-tools
start a new projet : ionic start hello blank ->ok
ionic platform add android -> ok
ionic build android - Error:
BUILD FAILED
C:\SDK\android-sdk\tools\ant\build.xml:954: The following error occurred while executing this line:
C:\SDK\android-sdk\tools\ant\build.xml:971: null returned: -1073741819
Total time: 2 seconds
D:\PROD\myapp\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,D:\PROD\myapp\platforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
ERROR building one of the platforms: Error: D:\PROD\myapp\platforms\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project
Paths are OK and if I start a new cordova projet (not ionic) build is a success.
If I check problem on c:\android-sdk\build.xml and I add
<echo>aapt: ${aapt}</echo>
I can see aapt.exe path is on android-21 (target is android-19)
For me, problem is I have two android sdk : android 19 and android 21. If I use CLI on windows, ionic/cordova choose android-21\aapt.exe by default and no android-19\aapt.exe
I tried to force Path with android version : %ANDROID_HOME%\build-tools\19.0.0 with no success.
To resolve this problem I changed paths to force on aapt executable path to point on android 19:
File c:\android-sdk\tools\ant\build.xml :
<aapt executable="C:\android-sdk\build-tools\19.0.0\aapt.exe" ...
</aapt>
This is not the best way, but I have not found another.
Instruction 1:
After adding your ANDROID_HOME, make sure you do the below:
Restart your System or run source ~/.bash_profile
Remove Android platform from your project ionic cordova platform rm android or ionic platform rm android
Add Android platform ionic cordova platform add android
Then ionic cordova run android or ionic run android
Instruction 2:
To set your ANDROID_HOME and JAVA_HOME, follow the below steps:
Run command open ~/.bash_profile
Paste the below in the file that opens on your Text editor
export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Save - "Command S" or "Ctrl S"
Then Follow the "Instruction 1:" above
NOTE: Make sure you have **24.4.1_1 SDK**
Hope this helps.
Related
I'm attempting to build a cordova application, starting from following the documentation for the hello world example.
When I build my application for android, it builds successfully, however when running.
cordova run android
I recieve the following error:
BUILD SUCCESSFUL in 2s
48 actionable tasks: 48 up-to-date
Built the following apk(s):
/Users/ivyjack/Sites/hello/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/ivyjack/Library/Android/sdk (recommended setting)
ANDROID_HOME=/Users/ivyjack/Library/Android/sdk (DEPRECATED)
Using Android SDK: /Users/ivyjack/Library/Android/sdk
Command failed with exit code 1: apkanalyzer manifest target-sdk /Users/ivyjack/Sites/hello/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Exception in thread "main" java.lang.IllegalStateException: Cannot locate latest build tools
at com.android.tools.apk.analyzer.AaptInvoker.getPathToAapt(AaptInvoker.java:99)
at com.android.tools.apk.analyzer.AaptInvoker.<init>(AaptInvoker.java:41)
at com.android.tools.apk.analyzer.ApkAnalyzerCli.getAaptInvokerFromSdk(ApkAnalyzerCli.java:278)
at com.android.tools.apk.analyzer.ApkAnalyzerCli.main(ApkAnalyzerCli.java:129)
I have updated my .zshrc file to include my paths:
#ANDROID SDK
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
I'm not sure what I am missing to be able to get the cordova application running for android? Any help would be appreciated.
I have encounter the same issue, and resolved by installing gradle
$ brew install gradle
NOTE : if you are using M1 you need additional shell settings for brew
(https://mac.install.guide/homebrew/3.html)
I am new to Ionic and created a simple application. I have installed Android Sdk. And added these Environment Variable
I am trying to build my app using cordova build commandcommand but getting this error :-
Error: cmd: Command failed with exit code ENOENT
I am been searching whole day for the solution and finally ended up here.
For linux, you'll also need to add these lines in ~/.bashrc file
export ANDROID_HOME='/home/your_username/Android/Sdk'
export ANDROID_SDK_ROOT='/home/your_username/Android/Sdk'
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin
Then check if android target is read with cordova requirements first.
Reference for Mac OS:
https://gist.github.com/kristopherjohnson/7568583
Command should be ionic platform add android and not cordova platform add android
I was getting the same error ...
In my case, it was occurring because of the changes in ionic CLI...
Now you need to run 'ionic cordova platform add android' (or ios) but the extension dont run this command yet...
I just insert 'cordova' in the source code of plugin (try to search the funcions that run the commands that start with 'ionic' and have to run 'cordova' together'
In the macOS, you find the source code at:
~/.vscode/extensions/vsmobile.cordova-tools-1.2.7/out/src/debugger/cordovaDebugAdapter.js
In the Windows, the path is:
C:\Users\yourusername\.vscode\extensions\vsmobile.cordova-tools-1.2.7\out\src\debugger\cordovaDebugAdapter.js
It worked for me...
I'm trying to build a default example app on Linux/Ubuntu 14.04 for Android.
I get a standard error message when doing sudo ionic build android:
Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
(see full log down below)
But if I do
echo $ANDROID_HOME && echo $JAVA_HOME && echo $ANT_HOME
/home/user3123726/Android/Sdk
/usr/lib/jvm/java-8-oracle
/usr/bin/ant
And command android and cordova are also available.
Android SDK is installed with all platform targets currently available (plus Android SDK Tools,Platform-Tools and Build tools)
npm 3.3.9 and Node 4.2.2 is installed
Cordova 5.3.3 was installed via npm
Ionic 1.7.7 was installed via npm
Apache Ant 1.9.3
ANDROID_HOME also defined on .bashrc:
export ANDROID_HOME=/home/user3123726/Android/Sdk
export PATH=${PATH}:/home/user3123726/Android/Sdk/platform-tools:/home/user3123726/Android/Sdk/tools
I have no idea what is the reason that the build process fails. Any help is appreciated - thanks!
Here full log of ionic project creation (basically create,add platform and build):
ionic start myApp tabs
Downloading: https://github.com/driftyco/ionic-app-base/archive/master.zip
[=============================] 100% 0.0s
Downloading: https://github.com/driftyco/ionic-starter-tabs/archive/master.zip
[=============================] 100% 0.0s
Updated the hooks
directory to have execute permissions Update Config.xml Initializing
cordova project
Your Ionic project is ready to go! Some quick tips: [... shortened]
cd myApp
sudo ionic platform add android
Updated the hooks directory to have execute permissions
Downloading Default Ionic Resources
Downloading: https://github.com/driftyco/ionic-default-resources/archive/master.zip
[=============================] 100% 0.0s
Done adding default Ionic resources
Adding icons for platform: android
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.ionicframework.myapp809922
Name: myApp
Activity: MainActivity
Android target: android-22
Copying template files...
Android project created with cordova-android#4.1.1
Running command:
/home/user3123726/testing/myApp/hooks/after_prepare/010_add_platform_class.js /home/user3123726/testing/myApp
add to body class: platform-android
Saving platform to package.json file
sudo ionic build android
Running command: /home/user3123726/testing/myApp/hooks/after_prepare/010_add_platform_class.js /home/user3123726/testing/myApp
add to body class: platform-android
Running command: /home/user3123726/testing/myApp/platforms/android/cordova/build
[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /home/user3123726/testing/myApp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/user3123726/testing/myApp/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
Fixed it:
Was a permission problem
sudo chown -R $(whoami) /home/user3123726/.cordova
to give cordova the rights
and did
ionic add platform android
ionic build android
without sudo ;)
Since yesterday, I have some problems with Cordova and Android. I can not create an functional Android App. iOS works.
In detail: I use a Mac (MacOS X 10.8.5) and have installed ADT 22.6.2 (with API 17/18/19) and added the sdk-tools to my PATH.
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/adt/sdk/tools:/Applications /adt/sdk/platform-tools:/usr/local/MacGPG2/bin
My configuration:
$ node -v
v0.10.26
$ cordova -v
3.4.1-0.1.0
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on June 20 2012
My attempt to create an Cordova App:
$ cordova create XY com.wb.XY XY
Creating a new cordova project with name "XY" and id "com.wb.XY" at location "/.../XY"
$ cd XY
XY wb$ cordova platform add ios
Creating ios project...
XY wb$ cordova platform add android
Creating android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.wb.XY
Name: XY
Android target: android-19
Copying template files...
Running: android update project --subprojects --path "platforms/android" --target android-19 --library "CordovaLib"
Resolved location of library project to: /.../XY/platforms/android/CordovaLib
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'XY'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/build.xml
Added file platforms/android/proguard-project.txt
Updated project.properties
Updated local.properties
No project name specified, using project folder name 'CordovaLib'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/CordovaLib/build.xml
Added file platforms/android/CordovaLib/proguard-project.txt
Project successfully created.
XY wb$ cordova platform list
Installed platforms: android 3.4.0, ios 3.4.1
Available platforms: amazon-fireos, blackberry10, firefoxos
XY wb$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
Fetching plugin "https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git" via git clone
Installing "org.apache.cordova.inappbrowser" for android
Installing "org.apache.cordova.inappbrowser" for ios
XY wb$
What is going wrong? There is no directory „gen“.
If I try to import the project into ADT/Eclipse, I got the message:
Errors occurred during the build.
Errors running builder 'Android Resource Manager' on project 'XY'.
Errors running builder 'Android Pre Compiler' on project 'XY'.
Path must include project and resource name: /XY
and
/XY/gen already exists but is not a source folder. Convert to a source folder or rename it.
Eclipse generates a folder called „gen“, but it is empty.
EDIT: Here is what I tried based on the input given in answers and comments:
I have installed Node.js and Cordova 3.4:
$ node -v
v0.10.26
$ cordova -v
3.4.1-0.1.0
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on June 20 2012
I have done this as you described with CLI.
The Android SDK is in the system path:
$ echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/adt/sdk/tools:/Applications/adt/sdk/platform-tools:/usr/local/MacGPG2/bin
Everything seems to be all right. Do you see any mistake? Do I need Apache Ant?
If I try to add android (without sudo), I have got the output shown in my question. Trying this as admin (with sudo), the result is the same.
With
$ cordova emulate android
I get:
...
BUILD SUCCESSFUL
Total time: 5 seconds
WARNING : no emulator specified, defaulting to Android_Tablet
Waiting for emulator...
2014-04-26 14:16:53.848 emulator64-arm[84081:f07] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find:
/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
emulator64-arm: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
Booting up emulator (this may take a while)........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
It takes a very long time . . . after 15 minutes I broke off. The log at Eclipse shows always returning the same messages.
But with
$ cordova run android
I am able to install and launch the app on my Android-device. But if I try to import the project into Eclipse, the file XY.java is shown with many errors.
Do you have any idea what could be the problem?
I am still able to work with my existing apps (iOS and Android), but I can not create a new one for Android.
I am sharing with you the steps to create android PhoneGap app with cordova 3.4 version :-
1) Download and install Node.js.
2) Run this command on your terminal :-
$ sudo npm install -g cordova
3) Then create your project using following command :-
$ cordova create hello com.example.hello HelloWorld
4) Then before adding any platform , run the following command....Replace the path of android sdk with your system path :-
$ export PATH=${PATH}:/Users/taruna/Documents/adt-bundle-mac-x86_64-20131030/sdk/platform-tools:/Users/taruna/Documents/adt-bundle-mac-x86_64-20131030/sdk/tools
5) Now add your platform using following command :-
$ sudo cordova platform add android
6) Now you can successfully run your project on emulator using following command :-
$ cordova emulate android
And its done now.
`
I followed the documentation and some tutorials on Phonegap to install it on Windows 7, but I'm stuck.
So far, I've installed Java 1.7.0_06, Ant-Apache 1.9.2, Eclipse, Android SDK with Android 4.3 (API 18), all Tools and all Extras in the SDK Manager), NodeJS 0.10.18 and Git.
I wrote all paths in the PATH variables in Windows it's look like this (decomposed) :
F:\nodejs;
F:\android-sdk\sdk\platform-tools;
F:\android-sdk\sdk\tools;
%JAVA_HOME%\bin;
%ANT_HOME%\bin;
C:\Program Files (x86)\Git\bin
Where %JAVA_HOME% and %ANT_HOME% have the right path, they give me the their version when I type java -version or ant -version in the CLI
So I went in the CLI, I installed Phonegap with the following command :
npm install -g phonegap
It give me the 3.0.0-0.14.3 version when I type phonegap -v.
Now, I went to my folder F:\apps and I created a new project with the following command :
phonegap create hello com.example.hello HelloWorld
Everything goes well, the files are created.
I went in the 'hello' folder, and I typed this command :
phonegap local build android
And there come the problem, I get this error :
[phonegap] adding the Android platform...
[error] The command `android` failed. Make sure you have the latest AndroidSDK installed, and the `android` command (inside the tools/ folder) added to your path. Output:
I tried this command too :
phonegap build android
But it get stuck at this, nothing happen next :
[phonegap] detecting Android SDK environment...
[phonegap] using the remote environment
[phonegap] compressing the app...
After lot's of research, I don't know what I can do anymore to find the problem, and I'm quiet new with all this CLI... So yeah, do you have any idea why the command 'android' failed ?
Thanks
Open environment variables, on the first part 'user variables' add new variable with this name android and the variable F:\android-sdk\sdk\tools;
Then edit the user variables PATH and add this at end of the line %android%;
close your CMD and try again.