cordova project generates apk in wrong path - android

I have switched to a mac from a windows. Now when I run 'cordova build android' it is building successfully and generating an apk in /platforms/android/build/outputs/apk/android-debug.apk but this apk isnt working properly.
On my windows machine I go through the exact same steps and it builds a working apk in a different directory - /platforms/android/ant-build/MainActivity-debug.apk.
You can see the the apks are named differently - the one generated from windows machine is right.
I thought it may have something to do with ant but I have the exact same version and it is running on the machine fine. I thought it could have something to do with the ant environment variable as well but I don't think thats it either. This is what I have
/Users/myMachine/apache-ant-1.9.4/bin
Does anyone have any ideas?

Related

React Native AppCenter build problem - "JAVA_HOME_11_X64"

I updated most app packages, updated gradle (distributionUrl=https://services.gradle.org/distributions/gradle-7.5-bin.zip) and gradle tools ('com.android.tools.build:gradle:7.3.0').
I can make apk file through android studio. I can work with the emulator.
I tried to build via AppCenter and got an error that I need to use JAVA 11.
In the builder configuration, I inserted the parameter - JAVA_HOME => $(JAVA_HOME_11_X64).
The build was assembled successfully.
But if I try to install apk on my phone I get an error (see screenshot)
Also, the size of the apk file has increased by 2 times, which is very strange.
I can't install the apk file created through the AppCenter.
Perhaps someone faced such a problem? I will be grateful for advice.
image

Trying to build an Ionic 4 app for Android but gradle, paths and variables aren't found even though I've already set them

everyone. I want to build an app for one of my clients. It's the first time I develop an app on Ionic 4 and at the time of building the apk, I couldn't do it.
I checked all the errors that the console prompted to me. At first, it seemed to be moving on, however, at a moment, the console prompted the following:
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/Cris/Library/Android/sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
[ERROR] An error occurred while running subprocess cordova.
cordova build android --release exited with exit code 1.
I have already done a research about this topic, and even though there are similar questions here on this website, I couldn't find any answer that solved my problem.
I have already defined the ANDROID_SDK_ROOT, the ANDROID_HOME and GRADLE_HOME. I checked all of those dirs to see if they worked, and they did so. I have already downloaded and set up the JDK variable and path as well.
I have installed Android Studio with the version of sdk API that I need for this development. Also, when I researched about gradle, I installed it with npm and manually (without counting the time it got installed automatically with Android Studio). HOWEVER!!! The console tells that gradle isn't installed, that Android paths aren't set or that they are deprecated (both options, actually), and that I have to do what I have already done several times.
Here I let you see the variables set:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${JAVA_HOME}/bin:$PATH
export ANDROID_HOME=/Users/Cris/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export GRADLE_HOME=/Users/Cris/Library/Gradle.0/bin
export PATH=$PATH:$GRADLE_HOME
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
Do you guys have any idea of how to proceed? Thank you before hand
GRADLE_HOME should be the root folder of the <gradle installation folder>, currently its pointing to <gradle installation folder>/bin it should look like following
export GRADLE_HOME=/Users/Cris/Library/Gradle.0
I have already overcame the problem with the following instructions:
When you want to build your app for Android with Ionic 4 on MAC, install Java (JDK), install Android Studio, install the API version you want to work with, install Homebrew (on its website there is a so easy-to-follow guide to install it) and install Gradle by writing the following command:
brew install gradle
Then, write the following command and copy the route of the gradle directory:
brew info gradle
Go to Ionic Framework Developer Resources for MAC
And follow the instructions to set up the paths. Don't forget to check if the example paths work just fine on your computer by doing it as the following example:
ls /Users/your-user/Library/gradle-5.4
If the "echo" of that line says that the directory exists, then it's okay and you must set that path the way it is. If the directory doesn't exists (as it'll happen in the case of the $GRADLE_HOME's path, you should paste the route that you copied some steps ago.
To corroborate that those paths exist on your MAC, besids saving them on your MAC's ~/.bash_profile, enter them one by one (exporting the variable and exporting its path) inside the MAC's terminal.
Then, as one of the last steps (I'm not going to describe how to sign your app, because it's explained on the link above), write on a console opened inside your project the following line:
sudo ionic cordova build android --prod
It's going to build your app for production, which releases you from signing your app in order to install it on your mobile device
IMPORTANT NOTE:
If you want to sign your app, you should run the following command before signing it (it replaces the last command I wrote above):
sudo ionic cordova build --release android
You can find more information about releasing your app without a signed key and how to sign it on this website's section:
Publishing Your App - Ionic Framework
Thank you for checking this answer out! :D

Can't install unsigned Cordova apk

I just built a basic Cordova image, but I can't install it on my Android phone.
It says the package is corrupted.
I have enabled "Trust unknown sources" and copied the file onto my Nexus 6P.
The build process doesn't throw any errors, it creates a android-release-unsigned.apk file as expected.
Had the same problem as you because I followed the guide I linked in the comments above; that guide is for building a release build, not a test build.
In order to build a test build, do:
cordova build android
Which should create a file called debug-build.apk
In addition, if you have an android device set up for development, you can run:
cordova run android --device

To add android in phonegap platform using cordova [duplicate]

Helo,
I am currently trying to build the base phonegapp android app that's automatically created, so I navigated to the directory... but when I use the command
phonegap build android
I just get this random error, as shown in the attatched picture.
Extra info
I am currently on Windows 8, and am completely new to making apps, and am new to the command line as well. Not very familiar with this stuff...
What I'm trying to do would be called 'compiling', right?
Yeah, I had the same problem yesterday - but with a little help of a colleague I got it!
Step by step tutorial (for Windows)
Install node js
Install phonegap using command line: npm install -g phonegap
Install Android SDK
Launch Android SDK Manager and install Android 4.4.2 (API19)
Because latest phonegap/cordova version requires this
Documentation for Android SDK and SDK Platform should be enough
Also update already existing packages
Create an environment variable called ANDROID_HOME which points to destination of Android SDK. e.g. C:\Users\You\AppData\Local\Android\android-sdk
Download Apache Ant and extract the archive somewhere
Create an environment variable called ANT_HOME which points to destination where you have extracted Ant
Install JDK (Java Development Kit) for your System. Before you are able to download, you have to accept the licence
Create an environment variable called JAVA_HOME which points to destination of JDK
If you want to add plugins via phonegap automatically you should also install GIT.
Last but not least you need to add the following directories to PATH environment variable:
%ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
Each folder is separated by a semicolon
Setting environment variables will take effect just for new command line windows. So you should reopen it, after the whole process.
Easy, isn't it? ;-)
Now you can use phonegap build android after you've created a new phonegap project. If you have your smartphone plugged via USB and installed the USB drivers, and activated the USB Debugging on smartphone, you may use
phonegap run android
And the ready build APK will be transfered and executed on your smartphone. Perfect for testing.
If you want to create a final release APK, go to
YOURPROJECT\platforms\android\ant-build
and enter ant release.
You'll find the final APKs in YOURPROJECT\platforms\android\bin.
They are unsigned, here is a Noob guide to signing an APK.
I have tested a Barcode Scanner example, and it works seamlessly.
Have fun!
also check android in cmd, if it says: 'xcopy' was not recognized.
then add to your path:
%SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System32\Wbem;
Armin's guide is perfect. But if you still fail you can do this.
Phonegap platform files stay in C:\Users[username].cordova\lib folder. Go there and remove android/ios/bb... driectory.
For best result run this command:
npm cache clear
After that try again, clean platfrom files will be download and build your project.

How do I put my cordova application on the android play store?

If there is official cordova documentation for this, I couldn't find it and would appreciate a link. I have run cordova run android to deploy to my phone. Things look good. Now I'm ready to turn this into an official app that users can download on the android play store? When I build my app it generates a file named "CordovaApp-debug.apk". That "debug" part makes me think this is the wrong file to work with, but I'm not sure how to generate the right file.
Deploying a hybrid app to the Google Play Store
These steps would work for Cordova, PhoneGap or Ionic. The only difference would be, wherever a call to cordova is placed, replace it with phonegap or ionic, for your particular scenario.
Once you are done with the development and are ready to deploy, follow these steps:
Open a command line window (Terminal on macOS and Linux OR Command Prompt on Windows).
Head over to the /path/to/your/project/, which we would refer to as the Project Root.
While at the project root, remove the "Console" plugin from your set of plugins.The command is: cordova plugin rm cordova-plugin-console
While still at the project root, use the cordova build command to create an APK for release distribution.The command is: cordova build --release android
The above process creates a file called android-release-unsigned.apk in the folder ProjectRoot/platforms/android/build/outputs/apk/
Sign and align the APK using the instructions at https://developer.android.com/studio/publish/app-signing.html#signing-manuallyAt the end of this step the APK which you get can be uploaded to the Play Store.
Note: As a newbie or a beginner, the last step may be a bit confusing as it was to me. One may run into a few issues and may have some questions as to what these commands are and where to find them.
Q1. What are jarsigner and keytool?
Ans: The Android App Signing instructions do tell you specifically what jarsigner and keytool are all about BUT it doesn't tell you where to find them if you run into a 'command not found error' on the command line window.
Thus, if you've got the Java Development Kit(JDK) added to your PATH variable, simply running the commands as in the Guide would work. BUT, if you don't have it in your PATH, you can always access them from the bin folder of your JDK installation.
Q2. Where is zipalign?
Ans: There is a high probability to not find the zipalign command and receive the 'command not found error'. You'd probably be googling zipalign and where to find it?
The zipalign utility is present within the Android SDK installation folder. On macOS, the default location is at, user-name/Library/Android/sdk/. If you head over to the folder you would find a bunch of other folders like docs, platform-tools, build-tools, tools, add-ons...
Open the build-tools folder. cd build-tools. In here, there would be a number of folders which are versioned according to the build tool-chain you are using in the Android SDK Manager. ZipAlign is available in each of these folders. I personally go for the folder with the latest version on it. Open Any.
On macOS or Linux you may have to use ./zipalign rather than simply typing in zipalign as the documentation mentions. On Windows, zipalign is good enough.

Categories

Resources