Installed apk doesn't start - android

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.

Related

Ionic 2: APK output corrupted on android device

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.

react-native compiled apk wont run on device

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.

Google Glass // System signature // Install APK in background

I want to download and install / remove APKs in background programmatically on a google glass device.
Steps i already tried:
Move APK to /system/priv-apps
Try to sign the APK with the system signature (I don't know if I signed it with the correct one)
Set the android sharedUserId to "android.uid.system" -> this gave me a permission error while installing
Can anybody help me getting my App signed by a system signature? I really do not want to code a shell script running on each boot..
I am also getting the following error while trying to exec the
pm install -r APK_PATH
command programmatically:
Error running exec(). Command: [su] Working Directory: null Environment: null
Please help me! :-)
According to this documentation, be noted that the APK needs to meet the following criteria:
It must be zip-aligned.
You must not make any changes to the package name or private signing key after this (the Android package manager does not allow upgrades if either of these changes).
It must be smaller than 50 megabytes.
It must be compiled using the latest version of the GDK.
To sign the APK based from this thread,
On top of signing Android 1.6 for Dream with certificates generated by
myself, I've also managed to sign my app with the platform certificate
and run it with the system sharedUserId. These are the steps I took:
Build and flash to your Dream your own Android using http://source.android.com/documentation/building-for-dream. Use the
mkkey.sh script on
http://pdk.android.com/online-pdk/guide/release_keys.html to create
new certificates, including x509 certificates before you do 'make'.
In the AndroidManifest.xml of your application: under the <manifest> element, add the attribute android:sharedUserId="android.uid.system".
Export an unsigned version of your Android application using Eclipse: right-click on the project >> Android Tools >> Export
Unsigned Application Package.
Use <root-of-android-source-tree>/out/host/<your-host>/framework/signapk.jar to sign your app using platform.x509.pem and platform.pk8 in <root-of-android-source-tree>/build/target/product/security
generated earlier:
java -jar signapk.jar platform.x509.pem platform.pk8 YourApp-unsigned.apk YourApp-signed.apk.
Install the app to your device:
adb install YourApp-signed.apk
Run your app
Use adb shell ps to confirm that your app is running as system.
Check these related forums:
How to sign Android app with system signature?
How can I sign my application with the system signature key?
Hope this helps!

Android INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES

I am getting the following error when I'm trying to install an APK with a higher version and same packageName over an existing one. The existing APK is a system app. It fails with the following error:
INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES
However when I manually inspect the 2 apks their certificates seem to match. I used the following command:
unzip -p $package META-INF/CERT.RSA | keytool -printcert
Is there a different parameter which might be affecting this?

Application Error - net::ERR_FILE_NOT_FOUND (file:///android_asset/www/index.html)

I am trying to build and run my Meteor app on Android. If I simply run
meteor run android-device
or
meteor run android-device --mobile-server http://<host>
It loads up on my device (LG-E988, Android version 4.4.2).
However, when I build the app into a .apk and run it on my device, it would not start. Here're my steps:
I have already added the platforms, added mobile-config.js etc. Here are my last steps:
Navigate into my project's directory and run:
$ meteor build ~/Desktop/project-build/ --server=http://<host>:<port> --verbose
I get a success message.
BUILD SUCCESSFUL
Total time: 2 mins 37.466 secs
Built the following apk(s): Android
Navigate to ~/Desktop/project-build/android/ and I find a project/ directory, a README and a release-unsigned.apk.
I then signed the release-unsigned.apk:
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /home/dayuloli/.keystore release-unsigned.apk <alias>
Then I verified that it has been signed:
$ jarsigner -verify -verbose -certs release-unsigned.apk
And the console printed jar verified..
Next I zipalign
$ $ANDROID_HOME/build-tools/23.0.2/zipalign 4 release-unsigned.apk production.apk
Sends the production.apk to my Android device. When I ran the app, I get an Application Error with the following message:
net::ERR_FILE_NOT_FOUND (file:///android_asset/www/index.html)
Observations
The app icon shows the cordova logo instead of the logo icons I specified in the mobile-config.js
When I unpacked the production.apk, I don't see a android_asset directory. But I do see a assets/www/ directory, but this has no index.html in it.
How can I resolve this issue?

Categories

Resources