Walkthrought with react-native tutorial (react-native 0.30):
I created app which couldn't be installed on android device here are steps:
react-native init demo
cd android
gradlew assembleRelease
Copying unsigned apk to mobile device ( htc m8 mini 2 )
and got result : Application demo was not installed
Based on this similiar question apk didn't run on mobile android react native:
Unsigned apk won't install on mobile.
But why I am able to run unsiged application made by Ionic 2?
Whats the problem?
In Ionic 2 you run a debug apk, its not possible to run an unsigned apk.
What you can do in react is sign your apk and run.
The first setup can be a little complex, but after you complete the setup is very easy to generate a signed apk when you need it.
You can follow these instructions to sign your apk:
Generating a signing key
You can generate a private signing key using keytool.
$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
This command prompts you for passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore.
The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app, so remember to take note of the alias.
Note: Remember to keep your keystore file private and never commit it to version control.
Setting up gradle variables
Place the my-release-key.keystore file under the android/app
directory in your project folder.
Edit the file ~/.gradle/gradle.properties and add the following
(replace ***** with the correct keystore password, alias and key
password),
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****
These are going to be global gradle variables, which we can later use in our gradle config to sign our app.
Note about saving the keystore: Once you publish the app on the Play
Store, you will need to republish your app under a different package
name (losing all downloads and ratings) if you want to change the
signing key at any point. So backup your keystore and don't forget the
passwords. Note about security: If you are not keen on storing your
passwords in plaintext and you are running OSX, you can also store
your credentials in the Keychain Access app. Then you can skip the two
last rows in ~/.gradle/gradle.properties.
Adding signing config to your app's gradle config
Edit the file android/app/build.gradle in your project folder and add the signing config,
...
android {
...
defaultConfig { ... }
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}
}
...
Generating the release APK
Simply run the following in a terminal:
$ cd android && ./gradlew assembleRelease
Gradle's assembleRelease will bundle all the JavaScript needed to run your app into the APK. If you need to change the way the JavaScript bundle and/or drawable resources are bundled (e.g. if you changed the default file/folder names or the general structure of the project), have a look at android/app/build.gradle to see how you can update it to reflect these changes.
The generated APK can be found under android/app/build/outputs/apk/app-release.apk, and is ready to be distributed.
Testing the release build of your app
Before uploading the release build to the Play Store, make sure you test it thoroughly. Install it on the device using:
$ cd android && ./gradlew installRelease
Note that installRelease is only available if you've set up signing as described above.
You can kill any running packager instances, all your and framework JavaScript code is bundled in the APK's assets.
#EvghenyKalkutin if you are beginner in react-native then just follow this simple step
Download chocolatey from your cmd just write this code in cmd #powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
after successfully install the chocolatey now install node.js and Python2 using chocolatey. for this use this code for install node.js choco install nodejs.install and install Python# use this code choco install python2
ok now open node.js command promt and run this code npm install -g react-native-cli to start react-native
ok now download sample project using this code react-native init AwesomeProject or react-native init HelloWorld :)
Now go to the directory where this project downloaded using cd AwesomeProject
Start android stduio and open this project and correct your gradle error if it occurs(and clean project) and connect your device with usb debugging
and check your device is available or not using this code adb devices
if device is available then convert it's port for the react native using this code adb reverse tcp:8081 tcp:8081
now perform this code npm start for the build node.js bridge
after build the node.js bridge now start your project using this code react-native run-android and here you go your sample project is run on your device
**And for unsign apk or assembleRelease just go through below step **
just write this code in node.js command prompt cd android && gradlew clean && gradlew assembleRelease
I use windows os so all this instructions are for windows os I don't know this code is same for mac os or linux os
i hope this wiil help you for start up in react-native. if any problem just comment it.
WINDOWS USERS
FOLLOW THESE INSTRUCTIONS ....IT WORKED FOR ME
Prerequisite - You must have a keystore file, If you don't have then Open cmd run keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000 follow instructions and you are done.You will have a keystore file. Now follow these steps.
1 .On windows cd android and then run gradlew assembleRelease in Editor Terminal or Command Prompt in your project directory.
2 .Find APK at this location
android/app/build/outputs/apk/release/app-release-unsigned.apk
3 .Copy this APK to bin folder of jdk installation directory ( for me directory was C:\Program Files\Java\jdk1.8.0_181\bin ) [ Basically in this step we are trying to go to the same directory as jarsigner]
4 .Also Copy your keystore file to this ( C:\Program Files\Java\jdk1.8.0_181\bin ) directory.
5 .Now Open cmd in Administrator mode and run
cd C:\Program Files\Java\jdk1.8.0_181\bin
6 .Now run
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <<your keystore file name >> <<your apk file name>> alias_name
Here goes your apk , now find your signed apk here cd C:\Program Files\Java\jdk1.8.0_181\bin . Install it, Now it should install.
Related
I have to write couple tests on Xamarin UI Test framework to check apk on emulator. I tried to install my apk in two ways:
1 adb.exe install path\com.company.mobiledemo.apk
2 through Xamarin UI Test
if (platform == Platform.Android)
{
AndroidApp app = ConfigureApp.Android
.ApkFile("path\\com.company.mobiledemo.apk")
.Debug()
.EnableLocalScreenshots()
.DeviceSerial("emulator-5554")
.StartApp();
return app;
}
In first approach apk installed and working correctly. But when apk installed via code above apk will be install but wont launch, just stopped after splash screen.
I have no idea why because both use the same apk file.
NUnit: 3.13.3
NUnit3TestAdapter: 4.2.1
Xamarin.UITest: 2.2.6
Emulator OS: Android 6.0 Api 23
Ok I found the solution. It's a bit confused and maybe there is a more easy fix. Problem as I understood is your apk and Instrumentation backend apk must be signed the same cert.
My steps:
I installed apk via adb command : >adb.exe install ~\..\com.company.mobiledemo.apk
Then changed AppInitializer.cs like this :
if (platform == Platform.Android)
{
string keystore = "~\\..\\..\\some.keystore";
AndroidAppConfigurator appConfigurator = ConfigureApp.Android
.KeyStore(
keystore,
"storePassword",
"keyPassword",
"\"keyAlias\""
)
.InstalledApp("com.company.mobiledemo.apk")
.Debug()
.EnableLocalScreenshots();
AndroidApp app = appConfigurator.StartApp(AppDataMode.Clear);
return app;
}
Then tried to launch test and got error :
System.Exception : Failed to execute: C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin\jarsigner.exe -sigalg SHA1withRSA -digestalg SHA1 -signedjar "C:\Users\{user}\AppData\Local\Temp\uitest\a-287A943C412ED6ED5DEB1675E7FDF91843FD0807\20344\SignedTestServer.apk" -storepass bla-bla -keypass bla-bla -keystore "~..\Mobile\Mobile.Android\Certificate\some.keystore" "C:\Users\{user}\AppData\Local\Temp\uitest\a-287A943C412ED6ED5DEB1675E7FDF91843FD0807\TestServer.apk" ""Key Alias"" - exit code: 1
Please type jarsigner -help for usage
Only one alias can be specified
It's ok.
Open folder from error message :
C:\Users{user}\AppData\Local\Temp\uitest\
You will see something like this :
Delete all and run tests once again. After launching new test data will appear:
Copy command from error message above, go to C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin or directory where located jarsigner.exe
Execute command after System.Exception : Failed to execute:
Find SignedTestServer.apk and copy it into folder containes dummy.apk
Run tests once again and see that FinalTestServer.apk appeared
PS Close folder C:\Users\{user}\AppData\Local\Temp\uitest before 9.
I already did buildozer android debug and have the .apk file installed and works fine, at least tested for one/two devices. This is also with the semi-default buildozer.spec, for example : the domain name is still org.test but with the name of the app is adjusted.
With this .apk file (after buildozer android debug process), is
this the one that is ready to be uploaded to playstore? or there is
still some other (technical) preparations?
I know that we may do beta test first before making it public. This is my first time coding an app with intention to publish it.
Thanks in advance.
You need to create a release version of your apk file before uploading to the Play Store. The debug version is just for testing on your phone. To create a release version and upload the app, you just have to follow these steps.
1. Create a Key
$ mkdir ~/keystores/
$ keytool -genkey -v -keystore ~/keystores/<your-new-key>.keystore -alias <your-key-alias> -keyalg RSA -keysize 2048 -validity 10000
2. Export some variables
$ export P4A_RELEASE_KEYSTORE=~/keystores/<your-new-key>.keystore
$ export P4A_RELEASE_KEYSTORE_PASSWD=android
$ export P4A_RELEASE_KEYALIAS_PASSWD=android
$ export P4A_RELEASE_KEYALIAS=<your-key-alias>
3. Make release apk
$ cd <your-project-folder>
$ buildozer -v android release
4. Finally, optimize it
$ ~/.buildozer/android/platform/android-sdk-20/build-tools/23.0.1/zipalign -v 4 ./bin/Your-App-0.1-release.apk ./bin/Your-App-0.1-release-optimized.apk
I have developed an app with Ionic 2 and would like to test it on an Android phone. Thus in my bash CLI, I tried to run several commands to build the APK, such as:
ionic cordova build android --release
ionic cordova build --release android
ionic cordova build android --release --prod
ionic cordova build android --prod
In the end, the APK file is generated, but when I transfer it on my android phone, it says the app is corrupted and it won't run.
Any ideas how to fix my problem? Thanks.
EDIT: I also tried to plug my phone by USB. adb devices returns a list showing that my device is indeed connected. Then I ran ionic cordova run android, but I get an error : Your Android platform does not have api.js.
ionic info output:
global packages:
#ionic/cli-utils : 1.4.0
Cordova CLI : 7.0.0
Ionic CLI : 3.4.0
local packages:
#ionic/app-scripts : 1.3.7
#ionic/cli-plugin-cordova : 1.4.0
#ionic/cli-plugin-ionic-angular : 1.3.1
Cordova Platforms : browser broken ios 4.4.0
Ionic Framework : ionic-angular 3.1.1
System:
Node : v6.10.3
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.10
I was facing the same issue, after a long R&D, I found the issue. As per my understanding, the issue is not with the Android build, its the generated unsigned APK that you are running on your mobile device. The fact is that system will not allow to install an application with unsigned instead, it will show the corrupt message. So whether you want to upload your application to Google Store or not you have to make the application signed so that the system will at least allow the application to install into the mobile device.
Kindly refer below step to generate signed APK
Step 1: Open command prompt and go to the JDK path's bin folder
Step 2: Now we need to create a new certificate/keystore to generate your private key using the keytool command that comes with the JDK.
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize
2048 -validity 10000 -alias my-alias
Or you can specify particular drive/folder where you want to generate keystore file
keytool -genkey -v -keystore D:\my-release-key.jks -keyalg RSA
-keysize 2048 -validity 10000 -alias my-alias
You’ll first be prompted to create a password for the keystore. Then, answer the rest of the nice tools' questions and when it’s all done, you should have a file called my-release-key.jks created in the current or specified directory.
Note: Make sure to save this file somewhere safe, if you lose it you won’t be able to submit updates to your app!
Step 3: To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore
my-release-key.jks android-release-unsigned.apk my-alias
Or use below one, do forgot to specify the exact path to keystore.jks and app-release-unsigned.apk file
jarsigner -verbose -sigalg SHA1withRSA -d igestalg SHA1 -keystore
D:\ionic_apk\my-release-key.jks
D:\Ionic...\platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk
my-alias
That's it, you have just build a signed APK. Rename the APKfile if required. Copy that on your mobile device and install it.
So if you want to optimize you APK, then we need to run the zip align tool which can be found in /path/to/Android/sdk/build-tools/VERSION/zipalign. For example, on OS X with Android Studio installed, zipalign is in ~/Library/Android/sdk/build-tools/VERSION/zipalign:
zipalign -v 4 android-release-unsigned.apk HelloWorld.apk
To verify that your APK is signed run apksigner. The apksigner can be also found in the same path as the zipalign tool:
apksigner verify HelloWorld.apk
Please use this guide: https://developer.android.com/studio/publish/app-signing#signapp
As #Prashob Thekkyal correctly have guessed, you have to signed the app before it can be installed by Android Nougat. That being said, jarsigner refuse to sign an apk file. You have to use the apksigner utility that is present in the android build-tools.
Cordova Platforms should be android x.x.x in your case.
Check root/platforms/platform.json it should be
{
"android": "x.x.x"
}
Make sure your android folder is in right place(root directory/platforms/android).
Try removing and adding the platform again.
I am trying to build a signed apk for Android platform using cordova.
I have already created unsigned apk using cordova --release android.
But i am unable to sign usejarsigner and zipalign.
kindly help.
I have already solved my problem.
I am explaining its steps for the people who are still stuck in it:
Create a unsigned apk.
Run this command cordova --release android after getting to the location of the project.
You can find the unsigned apk in
project_name\platforms\android\build\outputs\apk\android-release-unsigned.apk
Copy this apk and keystore tool in one folder.
Navigate to the folder and sign it using jarsigner present in java.
Run this command,
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <keystorename <Unsigned APK file> <Keystore Alias name>
After this you will be prompt to enter password of keystore.
Go to location of zipalign.
(it is present in Android\SDK\build-tools\version)
Run this command
zipalign -v 4 "location of signed apk" "location of aligned apk"
I'm trying to generate my release apk to deploy it on Play Store.
I'm running this command
Sudo cordova build android --release
Which is generating me a file named Android-Release-Unsigned.apk
I tried many solutions, like creating keystore
keytool -genkey -v -keystore key-name.keystore -alias alias-name -keyalg RSA -keysize 2048 -validity 10000
or the trick of creating a Ant.properties file like here and none of them worked at all.
Any other possible solution for this ? Cordova version is 5.1.1
Create a file called release-signing.properties and put in APPFOLDER\platforms\android folder Cordova used to use ant.properties but now ignores that file.
Contents of the file: edit after = for all except 2nd line
storeFile=C:/yourlocation/app.keystore
storeType=jks
keyAlias=aliasname
keyPassword=aliaspass
storePassword=password
Now running cordova build android --release should produce a signed version.
If you have keystore file generated, this should work.
You may also need to remove console plugin if the same apk directly goes to production.
In cordova 6.2.0
cd cordova/ #change to root cordova folder
platforms/android/cordova/clean #clean if you want
cordova build android --release -- --keystore="/path/to/keystore" --storePassword=password --alias=alias_name #password will be prompted if you have any
Sorry I couldn't comment. Possible duplicate?
How to create a signed APK file using Cordova command line interface?
This worked perfect for me.