I was trying to build an Ionic2 app with Android platform on my Win 7 (32 bt) system.
I ran the ionic build android command in the CLI and the following error occurred :
...ionic build android
> ionic-hello-world# ionic:build D:\<path>
> ionic-app-scripts build
[20:12:32] ionic-app-scripts 1.0.0
[20:12:32] build dev started ...
[20:12:32] clean started ...
[20:12:32] clean finished in 10 ms
[20:12:32] copy started ...
[20:12:32] transpile started ...
[20:12:37] transpile finished in 5.47 s
[20:12:37] webpack started ...
[20:12:38] copy finished in 5.74 s
[20:12:49] webpack finished in 11.84 s
[20:12:49] sass started ...
[20:12:52] sass finished in 2.81 s
[20:12:52] build dev finished in 20.16 s
[20:12:58] tslint: D:/../src/app/app.component.ts, line: 3
Unused import: 'OneSignal'
L2: import { Platform } from 'ionic-angular';
L3: import { StatusBar, Splashscreen, OneSignal } from 'ionic-native';
ANDROID_HOME=C:\Users\<user-name>\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
Subproject Path: CordovaLib
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
Then as suggested I read the 'https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html' and created the gradle.properties file with the following
org.gradle.daemon=true
The error still persists with the same result !!!
What is going wrong ?? Please help .
Found the solution after a hour long R&D.
Basically as per 'https://cordova.apache.org/docs/en/latest/guide/platforms/android/' - As of cordova-android#4.0.0, Cordova for Android projects are built using Gradle. Earlier it was built using Apache Ant.
Now Gradle looks for latest Android SDK. When I removed the android platform and added again with ionic platform add android command - the CLI listed that the latest Android SDK ( in my case it was SDK 24 ) was not installed.
I installed the required SDK version using Android SDK Manager and subsequent add of Android Platform along with the cordova plugin smoothly installed without any error.
The CLI printed the following -
..ionic plugin add onesignal-cordova-plugin
Fetching plugin "onesignal-cordova-plugin" via npm
Installing "onesignal-cordova-plugin" for android
ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121
Subproject Path: CordovaLib
Incremental java compilation is an incubating feature.
:clean
:CordovaLib:clean
BUILD SUCCESSFUL
Total time: 1.611 secs
Subproject Path: CordovaLib
Try using cordova platform add https://github.com/apache/cordova-android
Ive had to start using this command ever since updating Ionic.
Related
I am trying to follow a tutorial to build an Android app using Bazel as given here:
https://docs.bazel.build/versions/master/tutorial/android-app.html. The app is being built successfully with the command:
bazel build //src/main:app
However, when I try to run the app using the command bazel mobile-install //src/main:app the build is failing with the following error:
INFO: Analyzed target //src/main:app (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/kanzashaikh/examples/android/tutorial/src/main/BUILD:1:15: Installing //src/main:app failed: (Exit 1): incremental_install failed: error executing command bazel-out/darwin-py2-opt-exec-2B5CBBC6/bin/external/bazel_tools/tools/android/incremental_install --output_marker bazel-out/darwin-fastbuild/bin/src/main/app_files/full_deploy_marker --dexmanifest ... (remaining 11 argument(s) skipped)
Traceback (most recent call last):
File "/private/var/tmp/_bazel_kanzashaikh/df06cea5303c222cca918b7a24c9d8ca/execroot/main/bazel-out/darwin-py2-opt-exec-2B5CBBC6/bin/external/bazel_tools/tools/android/incremental_install.runfiles/bazel_tools/tools/android/incremental_install.py", line 25, in
from concurrent import futures
ImportError: No module named concurrent
Target //src/main:app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.311s, Critical Path: 0.19s
INFO: 3 processes: 3 internal.
FAILED: Build did NOT complete successfully
How to solve this issue?
It looks like bazel is using python2 (the py2 from darwin-py2-opt-exec-2B5CBBC6 from the file paths), but from concurrent import futures in incremental_install.py doesn't work in python2.
If you don't have python3 installed, try installing it and seeing if that fixes the problem.
If you do have python3 installed, then check your bazel version, older versions of bazel might be defaulting to python2.
When I run command
ionic cordova run android
build is succeeded but app cannot be run on my android device.
The error log is as:
BUILD SUCCESSFUL in 4m 7s
47 actionable tasks: 45 executed, 2 up-to-date
Built the following apk(s):
ANDROID_HOME=C:\Users\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_121
No target specified, deploying to device 'UGM0217321003049'.
Skipping build...
Built the following apk(s):
Error: Could not find apk architecture: arm build-type: debug
[ERROR] An error occurred while running subprocess cordova.
cordova run android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
Under the directory platforms/android/build/outputs/apk, there is only one folder called debug under which there are two file android-debug.apk and output.json.
apk
|---debug
|---android-debug.apk
|---output.json
I suspect there should be some arm architecture file in apk directory, but I don't know how to generate it.
Can you help me to solve this run android error?
To avoid extended discussions in comments, let me summarise the workaround as below:
Try to run below command to build the apk first.
cordova build android
or
ionic cordova build android
Look for the apk from platforms\android and manually install it.
How to automatically build the android-debug.apk in app folder?
the .json file is auto generated, usually you don't need to touch it.
By default, the apk path is under app/build/outputs/apk, you can copy it to a custom location wherever you prefer, for your case, maybe it is app/ root directory. You can do this with many means, e.g. bash scripts. Below gradle snippets is how I do this task, just copy below code to the end of your app/build.gradle:
def capitalizeFirstLetter(s) { s[0].toUpperCase() + s[1..-1] }
def publish = project.tasks.create("copyApks")
publish.description "Copies apks to custom directory"
android.applicationVariants.all { variant ->
def customPath
variant.outputs.all {
customPath = "$projectDir"
def capitalizedVariantName = capitalizeFirstLetter(variant.name)
def task = project.tasks.create("copy${capitalizedVariantName}Apk", Copy)
task.from(outputFile)
task.into(customPath)
task.dependsOn variant.assemble
publish.dependsOn task
}
}
From your command line, run ./gradlew copyApks or gradlew copyApks on macOS or Windows respectively.
Then you will find your apk is under app\ directory.
Here is a PATH in environment :
C:\Users\user\AppData\Roaming\npm;D:\work\SDK\SoftPhonegap\ADT\sdk\platform-tools;D:\work\SDK\SoftPhonegap\ADT\sdk\tools;D:\work\SDK\SoftPhonegap\apache-ant-1.9.5\bin;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Java\jdk1.7.0_51\bin;C:\Program Files\Java\jdk1.8.0_45\bin;D:\work\SDK\SoftPhonegap\ADT\sdk\build-tools
A. Error log of cordova build android
BUILD FAILED
D:\work\SDK\SoftPhonegap\ADT\sdk\tools\ant\build.xml:601: The following error oc
curred while executing this line:
D:\work\SDK\SoftPhonegap\ADT\sdk\tools\ant\build.xml:542: Unable to resolve proj
ect target 'android-21'
Total time: 0 seconds
D:\work\SDK\SoftPhonegap\ADT\hello\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:\work\SDK\SoftPho
negap\ADT\hello\platforms\android\build.xml -Dout.dir=ant-build -Dgen.absolute.d
ir=ant-gen"
ERROR building one of the platforms: Error: D:\work\SDK\SoftPhonegap\ADT\hello\p
latforms\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: D:\work\SDK\SoftPhonegap\ADT\hello\platforms\android\cordova\build.bat: C
ommand failed with exit code 8
at ChildProcess.whenDone (C:\Users\user\AppData\Roaming\npm\node_modules\cor
dova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
B Error log of Ant
C:\Users\user>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.
0_45\lib\tools.jar
Buildfile: build.xml does not exist!
Build failed
C. when add platform android
D:\work\SDK\SoftPhonegap\ADT\hello>cordova platform add android
npm http GET https://registry.npmjs.org/cordova-android/3.7.2
npm http 304 https://registry.npmjs.org/cordova-android/3.7.2
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.example.hello
Name: HelloWorld
Android target: android-21
Copying template files...
Project successfully created.
Installing "com.phonegap.plugins.PushPlugin" for android
Installing "com.salesforce" for android
Installing "org.apache.cordova.device" for android
Could not run SalesforceMobileSDK plugin android pre-install script
You are running node v0.10.25
You need to be running node 0.12 or above
You won't be able to successfully run: cordova build
Running SalesforceMobileSDK plugin android post-install script
The "android" utility does not exist at D:\work\SDK\SoftPhonegap\ADT\sdk\tools;D
:\work\SDK\SoftPhonegap\ADT\sdk\platform-tools\tools\android.bat. Make sure you
've properly installed the Android SDK.
I think you need to give platform_tools pah also, you should post your error log,
anyway here is how my PATH looks like
C:\Users\amitabhs\AppData\Roaming\npm;F:\Softs\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\platform-tools;F:\Softs\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\tools;F:\Softs\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\platforms;C:\Program Files\Java\jdk1.8.0_45\bin;C:\Program Files\apache-ant-1.9.5\bin;
check if it helps
Compile your project in https://build.phonegap.com/
There you have no problems with OS and can compile for all OS.
I use then for IOS compilation.
Solution:
Uninstall node v0.10.25
install node 0.12 or above
remove platform android (cordova platform rm android)
add platform android (cordova platform add android)
build android (cordova build android)
Done
I'm trying to build Android projects on the OSX (Mavericks 10.9.5) command line using this how-to: http://developer.android.com/tools/building/building-cmdline.html.
This How-To explains the use of assembleDebug/assembleRelease to build an Android project.
Unfortunately gradle doesn't create the assembleDebug or assembleRelease targets.
Executing ./gradlew assembleDebug returns this:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'assembleDebug' not found in root project 'test'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.826 secs
Steps:
android create project
The test project has been created with android create project --path . --name "DummyAPK" --target android-21 --package com.dummyapk.dummyapk --activity DummyActivity
which returned
Created directory /Users/user/Documents/test/src/com/dummyapk/dummyapk
Added file ./src/com/dummyapk/dummyapk/DummyActivity.java
Created directory /Users/user/Documents/test/res
Created directory /Users/user/Documents/test/bin
Created directory /Users/user/Documents/test/libs
Created directory /Users/user/Documents/test/res/values
Added file ./res/values/strings.xml
Created directory /Users/user/Documents/test/res/layout
Added file ./res/layout/main.xml
Created directory /Users/user/Documents/test/res/drawable-xhdpi
Created directory /Users/user/Documents/test/res/drawable-hdpi
Created directory /Users/user/Documents/test/res/drawable-mdpi
Created directory /Users/user/Documents/test/res/drawable-ldpi
Added file ./AndroidManifest.xml
Added file ./build.xml
Added file ./proguard-project.txt
gradle init
After that I executed gradle init, which returned
:wrapper
:init
BUILD SUCCESSFUL
gradlew tasks
Querying the available tasks with gradlew tasks returns (isn't there missing something?)
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project 'test'. [incubating]
dependencies - Displays all dependencies declared in root project 'test'.
dependencyInsight - Displays the insight into a specific dependency in root project 'test'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'test'.
properties - Displays the properties of root project 'test'.
tasks - Displays the tasks runnable from root project 'test'.
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 3.474 secs
My Java version is
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
..and Gradle version (installed via brew) is
------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_60 (Oracle Corporation 24.60-b09)
OS: Mac OS X 10.9.5 x86_64
What am I missing to be able to build an Android project on the command line?
android create project does not create a gradle friendly structure. It creates an ant friendly structure. You have two options depending on your intentions.
use ant to build your project ( not currently supported by Android team )
use Android Studio to generate a gradle friendly project structure.
num 2 is the recommended approach by the Android team. It's as simple as dl'ing Android Studio and creating a new project. From there you should be able to create a new project that can be built with ./gradlew build
try This:
./android create project -p AppPAKTGV -a Main -k com.example.apppaktgv -t android-23 -g -v 0.11.+
it's works but when i try target 24 or 25 not work i don't now
Try to do this and note
a) you need to type tools/android under Step 3 (like step 2: Execute)
-- but as said the ant structure is not helpful
-- not sure I can go from there
b) I follow the advice and also ensure get the platform-tools
-- I can build
-- I can get that .apk
-- I can adb install (I rename any existing .apk)
Seems working!
i am new to ionic, trying to get an apk for debugging i used the following commands inside the project directory:
ionic cordova platform add android
i did get "platforms/android" directory
and then i used:
ionic cordova build android
this is what i get after:
ionic-app-scripts build --target cordova --platform android
[23:57:19] ionic-app-scripts 3.1.10
[23:57:19] build dev started ...
[23:57:19] clean started ...
[23:57:19] clean finished in 10 ms
[23:57:19] copy started ...
[23:57:19] deeplinks started ...
[23:57:19] deeplinks finished in 36 ms
[23:57:19] transpile started ...
[23:57:27] transpile finished in 8.13 s
[23:57:27] preprocess started ...
[23:57:27] preprocess finished in less than 1 ms
[23:57:27] webpack started ...
[23:57:28] copy finished in 8.97 s
[23:57:35] webpack finished in 7.63 s
[23:57:35] sass started ...
Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.
[23:57:40] sass finished in 4.83 s
[23:57:40] postprocess started ...
[23:57:40] postprocess finished in 28 ms
[23:57:40] lint started ...
[23:57:40] build dev finished in 20.79 s
[23:57:44] lint finished in 3.91 s
> cordova build android
You have been opted out of telemetry. To change this, run: cordova telemetry on.
Android Studio project detected
(node:12696) UnhandledPromiseRejectionWarning: CordovaError: Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
at C:\Users\h2001\Desktop\myApp\platforms\android\cordova\lib\check_reqs.js:305:19
at _fulfilled (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:854:54)
at self.promiseDispatch.done (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:883:30)
at Promise.promise.promiseDispatch (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:816:13)
at C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:877:14
at runSingle (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:137:13)
at flush (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:12696) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12696) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
but i didn't get the promised \build\outputs\apk, what is the problem?
UPDATE: i installed android studio and updated it, still getting
(node:12696) UnhandledPromiseRejectionWarning
UPDATE: the problem was solved, turns out i had java10 which wont work with android, simply installing java8 solved the problem
btw, i dont have android sdk installed if that makes any difference?
You have answered your own question.
To make an Android APK
You need Java SDK 1.8.
Android SDK with latest build tools and platforms
JAVA_HOME & ANDROID_HOME environmental variables set correctly.
Also You need updated X-Code on a Mac to create an IPA.
You probably doesn't have android environment variable in your PC.
if you are running MAC try running:
sudo export ANDROID_HOME=/<installation location>/android-sdk-macosx
sudo export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
If you are running Linux then:
export ANDROID_HOME=/<installation location>/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
And if you are running Windows then open your command prompt as Administrator and run:
set ANDROID_HOME=C:\<installation location>\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
It will add enviroment variable to your system.