Failed to build apk via Gradle - android

I'm trying to build apk from my Ionic project via gradle but it shows the following error:-
Note: I've tried the following solutions which didn't work for me:-
1) Removed nodejs, clear all directories related to nodejs, cordova, ionic, gradle and do fresh installation.
2) Change distribution url in graddle-wrapper.properties file in project folder to distributionUrl=https://services.gradle.org/distributions/gradle-1.12-all.zip and build again.
3) Installed ant4windows and executed $ rm -r ~/.gradle and hoping that ant will do the magic.
4) Downloaded gradle-2.12-bin.zip & replaced the 'gradle 2.2.1 zip' file in PC-User/.gradle/.. folder . but it still fetches gradle 2.2.1 zip & shows exception
Some days ago I successfully created my apk following https://www.youtube.com/watch?v=qVOwGyQB3DQ & the apk was built using ant. Also tell why gradle is taking over the ant this time?

Related

Moodle Mobile 3.7.0

After downloading Moodle Mobile2 from github at https://github.com/moodlehq/moodlemobile2 so now its a zip file on my computer. In simple steps how do i get to publish this on googleplay?
I have tried renaming the zipfile to .apk then used advanced apktool to sign and recompile but when uploading to google play i get:-
Upload failed
Your APK cannot be analyzed using aapt. Error output:
Failed to run aapt dump badging:
ERROR: dump failed because no AndroidManifest.xml found
Obviously things are not so simple. If someone can help me with some basic steps from zip file to apk and publish i would be grateful as i am trying to self learn the process but need some help.
Thanks guys
It is definitely not so simple as to download the repository :) The detailed steps (from 1 to 9) are listed in the official documentation here: https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2
Summarizing the documentation and from my own experience you need to:
Install all building tools dependencies, at the time I'm writing this (Aug '19) those are: node v8.12.x or v11.12.x, cordova 8.1.2, ionic, gulp
Install additional tools for MacOSX or Windows if you are using any of those SOs (see doc page linked above).
Clone the repository with git clone or unzip it after downloading the zipped repository
To prepare the iOS and Android platforms (that allows you to build the binaries later on) go inside your project folder (unzipped or cloned folder) and run (from a terminal):
$ npm install
$ cordova prepare
$ gulp
Resolve any compatibility issues among packages that may have arised.
Apply the npm packages fixes to build for production with AOT listed in step 9 of the documentation page I linked above.
Build the apk from the terminal:
$ npm run ionic:build -- --prod
$ cordova build android --release
At this point you will have the compiled apk ready to be signed and uploaded to the Google Store.

Some question about Cordova build process for Android

I started learning Ionic, created an app, run it on browser and android emulator. Everything seems fine. I'm just curious about a few things but unfortunately couldn't find anything specific on them.
When I run the command ionic cordova build android, following lines appear on the console -
> ionic-app-scripts build --target cordova --platform android
[13:16:50] ionic-app-scripts 3.2.1
(--- SOME MORE LINES ---)
> cordova build android
Android Studio project detected
ANDROID_HOME=C:\Users\atiyar\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_202
studio
Welcome to Gradle 4.10.1!
Here are the highlights of this release:
(--- SOME MORE LINES ---)
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :wrapper
BUILD SUCCESSFUL in 1m 20s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip
.....................................................................................
Starting a Gradle Daemon (subsequent builds will be faster)
Download https://maven.google.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
(--- 257 MORE DOWNLOADS --- )
(--- SOME MORE LINES ---)
BUILD SUCCESSFUL in 47m 52s
46 actionable tasks: 46 executed
Built the following apk(s):
D:\Code\Ionic\IonicSideMenuApp\platforms\android\app\build\outputs\apk\debug\app-debug.apk
I wanted to know -
Why the project is identified as "Android Studio project"?
I created the project using Ionic CLI.
Why is it downloading gradle-4.1-all.zip?
As instructed here, I installed the latest version (5.2.1) of Gradle and added it to the PATH
What are all those .pom and .jar files (downloaded after gradle-4.1-all.zip) used for?
I never worked with Gradle build system before
Looks like the downloaded files get stored in C:\Users\UserName\.gradle directory
If these are the files used to build the app then how is the main gradle binary used with them?
If that is "how gradle works", could you please suggest a simplified resource to learn about it? I tried gradle documentation.
How did it identify Gradle 4.10.1?
I found gradle-4.10.1 on my machine in the Android Studio installation directory, but it's not added to the PATH
So, it seems I'm trying to have a clear picture of "under-the-hood of Cordova build process for Android". Any suggestion will be appreciated.
Cordova is, essentially, just a web page on top of a native Android project. Your cordova app runs in a native project's WebView. Ionic runs on top of Cordova
Native android projects use gradle as its build tool
.pom files are configuration files of native android third-party dependencies, e.g. config.xml for a cordova plugin; .jar is a java archive, the third-party dependency, in your case
I don't quite understand the question, but gradle isn't really anything you need to worry about as a Cordova developer. Android Studio runs in its own sandbox, your global gradle does not affect the sandbox. Do not upgrade the gradle of that sandbox, it might break your cordova project
cordova-android is what sets the gradle version in your native project

How to install app on android with gradlew.sh?

I have downloaded an android app from Github (Link). But I am unable to install this app on android (I am using Linux). Could someone tell me which direction should I go?
App folder Contains following files:
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle
first install gradle this linke
then you can build the project on Command Line './gradlew assembleDebug'
This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/. The file is already signed with the debug key and aligned with zipalign, so you can immediately install it on a device.

Phonegap 3.3 Build Android Failed

I'm trying to build a project but when I type: cordova build android the following error occurred:
Generating config.xml from defaults
for platform "android"
Preparing android project
Compiling app on platform "android"
via command "../platforms/android/cordova/build"
Error: An error occurred
while building the android project.Error executing "ant debug -f "../platforms/android/build.xml"":BUILD FAILED /usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:932:The following error occurred
while executing this line: /usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:950:null returned: 1
Total time: 18 seconds
at ChildProcess. < anonymous > (/usr/local/lib/node_modules/cordova/src/compile.js:65:22)
at ChildProcess.EventEmitter.emit(events.js: 98: 17)
at maybeClose(child_process.js: 735: 16)
at Socket. < anonymous > (child_process.js: 948: 11)
at Socket.EventEmitter.emit(events.js: 95: 17)
at Pipe.close(net.js: 466: 12)
Is there a fix for this problem?
EDIT
I used brew to install Android-SDK and installed all possible build-tools:
And my android manifest looks like:
EDIT2
As requested here is the responce for cordova build android --verbose: http://pastebin.com/rqdkVKYG
I found the bug.
While testing, reinstalling android-sdk and ant. I tried to create a new project. Than typed in the terminal cordova build and it build flawlessly. After this I copied my existing WWW folder in to the new project. Typed cordova build again, it gave an error. Now I knew that the bug was in my WWW folder and not in the project itself. Scanning my folders I noticed a file with no extension(hidden files). I deleted the file and tried again. Success!
SUMMARY:
Scan your folders for files without extensions and delete or move them. Cordova doesn't like those.
EDIT
If this doesn't work try:
cordova platform rm android
then reinstall android using :
cordova platform add android
Now try to build.
try to run the command $home/.cordova/lib/android/cordova/3.3.0/bin/check_reqs to check if you have all the required components installed for android.
¿Did you add to windows path the sdk?
You can also try:
cordova platform add android
cordova build
try ant -v in your terminal and make sure it's above 1.8. Cordova requires that.
Also check path is given correct for Ant, Android-SDK/tools, and Android-SDK/platformtools
To debug exact issue try $Cordova build android --verbose
Let me know.

Cordova 3.3.x - Android CordovaLib

When was the cordova.jar file removed from Cordova and replaced with CordovaLib? I was previously running Cordova 3.1.0-0.1.0.
Today I have upgraded to Cordova 3.3.0 (which was quite a headache, but I've completed the upgrade) and I've noticed a difference in my Android project structure: Cordova has created my project (with what I've named it) and it has also created -CordovaLibs.
Is this right? I know iOS it does this - but not Android (as I say, usually a JAR is added).
It's introduced in 3.3, had me baffled too.
Cordova 3.3 release notes:
http://cordova.apache.org/announcements/2013/12/16/cordova-330.html
CB-5232 Change create script to use Cordova as a Library Project
instead of a .jar
To generate file cordova3.3.0.jar, just follow these steps bellow:
Open your cmd, and go to the root folder where Cordova is installed:
$ cd ~/.cordova/lib/android/cordova/3.3.0/framework
Run the following command, notice the trailing dot
$ android update project -p .
Use ant to generate file jar. Be sure you have configure PATH for
$ ant jar
Now, you can copy file cordova3.3.0.jar to libs directory and import to your project. Hope it's helpful

Categories

Resources