I need to compile an application with system permissions in order to use target application com.android.settings. For now while I try to run my apk I get the error message
Test run failed: Permission Denial:
starting instrumentation
ComponentInfo{com.jayway.test/android.test.InstrumentationTestRunner}
from pid=354, uid=354 not allowed
because package com.jayway.test does
not have a signature matching the
target com.android.settings
How can I compile my application with system permissions?
After having some search I found how to sign my application with system (platform) key.
System signatures are located in directory <root-of-android-source-tree>/build/target/product/security. You can use them to sign your application with system privileges.
Add to manifest android:sharedUserId="android.uid.system"
Download System signatures files:
platform.x509.pem
platform.pk8
link:
https://android.googlesource.com/platform/build/+/android-8.0.0_r17/target/product/security/
Sign app through terminal (java -jar signapk.jar platform.x509.pem platform.pk8 unsigned.apk signed.apk) (first you must put all files to one folder), or make certificate with keytool-importkeypair to make google_certificate.keystore and then
link for keytool-importkeypair download and explanation:
https://github.com/getfatday/keytool-importkeypair
After that steps install your signed system app to your device. Good luck!!!
The anser for me was simply delete the debug.keystore file. The default storage location for AVDs is in ~/.android/ on OS X and Linux, in C:\Documents and Settings\.android\ on Windows XP, and in C:\Users\.android\ on Windows Vista.
In Eclipse I "cleaned" the project, uninstalled the App and the TestApp from the emulator and - voila everything ran fine again.
Related
I built my project using the new Android App Bundle format. With APK files, I can download the APK to my device, open it, and immediately install the app. I downloaded my app as a bundle (.aab format) and my Nexus 5X running Android 8.1 can't open the file. Is there any way to install AABs on devices in the same convenient manner as APKs?
Short answer:
Not directly.
Longer answer:
Android App Bundles is the default publishing format for apps on the Google Play Store. But Android devices require .apk files to install applications.
The Play Store or any other source that you're installing from will extract apks from the bundle, sign each one and then install them specific to the target device.
The conversion from .aab to .apk is done via bundletool.
You can use Internal App Sharing to upload a debuggable build of your app to the Play Store and share it with testers.
For MAC:
brew install bundletool
bundletool build-apks --bundle=app-release.aab --output=app-release.apks
bundletool install-apks --apks=app-release.apks
Installing the aab directly from the device, I couldn't find a way for that.
But there is a way to install it through your command line using the following documentation You can install apk to a device through BundleTool
According to "#Albert Vila Calvo" comment he noted that to install bundletools using HomeBrew use brew install bundletool
You can now install extract apks from aab file and install it to a device
Extracting apk files from through the next command
java -jar bundletool-all-0.3.3.jar build-apks --bundle=bundle.aab --output=app.apks --ks=my-release-key.keystore --ks-key-alias=alias --ks-pass=pass:password
Arguments:
--bundle -> Android Bundle .aab file
--output -> Destination and file name for the generated apk file
--ks -> Keystore file used to generate the Android Bundle
--ks-key-alias -> Alias for keystore file
--ks-pass -> Password for Alias file (Please note the 'pass' prefix before password value)
Then you will have a file with extension .apks
So now you need to install it to a device
java -jar bundletool-all-0.6.0.jar install-apks --adb=/android-sdk/platform-tools/adb --apks=app.apks
Arguments:
--adb -> Path to adb file
--apks -> Apks file need to be installed
If you want to install apk from your aab to your device for testing purpose then you need to edit the configuration before running it on the connected device.
Go to Edit Configurations
Select the Deploy dropdown and change it from "Default apk" to "APK from app bundle".
Apply the changes and then run it on the device connected. Build time will increase after making this change.
This will install an apk directly on the device connected from the aab.
You cannot install app bundle [NAME].aab directly to android device because it is publishing format, but there is way to extract the required apk from bundle and install it to you device, the process is as follow
Download bundletool from here
run this in your terminal,
java -jar bundletool.jar build-apks --bundle=bundleapp.aab --output=out_bundle_archive_set.apks
Last step will generate a file named as out_bundle_archive_set.apks, just rename it to out_bundle_archive_set.zip and extract the zip file, jump into the folder out_bundle_archive_set > standalones, where you will seee a list of all the apks
There goes the reference from android developers for bundle tools link
For those, who want single universal.apk that can run on every android device:
brew install bundletool
bundletool build-apks --mode universal --bundle ./app-release.aab --output ./app.apks
mv app.apks app.zip
unzip app.zip
Now, you can get your universal.apk
This worked for me on a mac.
You need to use a tool called bundletool You can install it incase if not already installed using brew
brew install bundletool
Run this command to extract and store the apks file at the desired location
bundletool build-apks --bundle=path/to/app-release.aab --output=/path/to/output/app.apks --local-testing
Install on a connected Android device
bundletool install-apks --apks=/path/to/output/app.apks
I have noted the complete command with output in a gist here https://gist.github.com/maheshmnj/6f5debbfae2b8183d94ca789d081f026
If you're using Maui at this point Visual Studio 2022 only creates AAB files; however, you can create an APK from a command line.
Change directory to where your project is located and run this:
dotnet publish -f:net6.0-android -c:Release /p:AndroidSigningKeyPass=blah
If you want to install the APP bundle without using PLAY STORE, You need to change your build variant to "release" at Android studio.
If you cannot build App yourself but have a release bundle, then refer to the most popular answer.
Go to Android Studio > Build > Select Build Variant..
Once you do this your build configuration may start showing errors.
This is because you now need to provide signing details in this configuration as well (this refers signing details from build.gradle)
you may either Edit the configuration and go to the Fix button at the bottom which will ask you to fill in signing details.
Or you may edit the build.gradle
Make sure you provide buildTypes {} and signingConfigs {}
android {
signingConfigs {
release {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
debug {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
}
compileSdkVersion 32
defaultConfig {
....
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug
{
signingConfig signingConfigs.debug
}
}
...
}
dependencies {
...
}
There is one or two minutes of delay before Android Studio starts reflecting correctly. Otherwise, you may do a clean rebuild and then run the app.
When you run the app this time it will be installed in release mode on the target device.
You may need a way to identify the Build Variant of the installed app. You may show the build name and variant somewhere in your app. Or if you have a button somewhere which shows only in debug mode you can check that.
If you have the project you can just build an app with android studio or push it directly to the device if you run a debug or release config with the device connected and selected as the target so long as you enable adb in developer mode on the device and tap trust this computer when you connect it to your machine.
But if you have the bundle because you're trying to install an app pulled from one phone onto another, there are free online services that convert play store links into a direct download of the apk. Just turn on add debugging on the device and adb install <path-to-apk> from the terminal.
If you have more than one device connected with adb enabled you can adb devices to get a list of their identifiers and adb install <path-to-apk> <device-id> will work as well. Or you can use adb to your advantage and do many things on multiple devices at once depending on your needs. There's even ways to adb over wifi.
You will need adb from the android-sdk tools to do any of this though, with Android Studio installed you would have a local installation already but it may not be in your path. However studios terminal likely has access to it since it would be the sdk path your IDE has saved in preferences.. If not you can download a standalone sdk/find out which one studio is using from it's preferences and either
Add adb from the platform-tools directory of said sdk it to your path (best)
Invoke adb from it's absolute path you just located and just keep hitting up to re-use your last command, swapping out the apk/device
cd to the adb directory and just use it with the full path to each of your apks (easiest)
For Windows 11:
PS C:/folder-with-aab-file> java -jar C:\dev\bundletool-all-1.9.1\bundletool.jar build-apks --bundle=app-release.aab --output=app-release.aab.apks --mode=universal
PS C:/folder-with-aab-file> ren app-release.aab.apks app-release.aab.apks.zip
After descompact zip file, the apk file'll with the name: universal.apk
Is there any way to install AABs on devices in the same convenient manner as APKs?
As installing is done by third party apps or mobile company file manager like apps.
The upcoming file managers versions, hence forth, will come with "aab" managing tools.
I searched "android aab installer" on playstore and found one.
deliberately not naming it.
The one I installed, extracted the bundle online,
But after that this app wasn't able to install this extracted app by itself (on my mi [miui] device ).
But this application saved the online extracted apk on phone memory, from where I was able to install it.
remember:
Google's "files" application wasn't able to install this apkbutmy system (in built) filer manager was able to.
Use (on Linux):
cd android
./gradlew assemblyRelease|assemblyDebug
An unsigned APK is generated for each case (for debug or testing)
NOTE: On Windows, replace gradle executable for gradlew.bat
I have installed Android Studio in the F:\ drive. My Flutter project is in the E:\ drive.
The Flutter plugin is installed in the Android Studio. But when I open my project in Android Studio and I go to the SDK Manager, it shows the following error:
The android sdk location cannot be at the filesystem root
Every package is disabled and the checkboxes are disabled, so I cannot click them to install Android SDK. The "Edit" link next to the error is not working either.
I came with the same problem because of forgetting "sudo"
Using the new android studio (bumble bee version) .
Restart the app and make sure you have an internet access
That will be enough to create the SDK and it’s directories
Just press Edit ( It is clickable) then download and install the required components.
Download the SDK first, and restore the default settings.
You can find the "Restore default settings" feature here.
What you can do is that you click on edit to surely you will get some version of Android that installs it by default and you click on next it will open another configuration verification window and you click on the next one for last it will tell you or It will update the version of android that was downloaded by default and you click again to finish and you can just select other versions of Android. That worked for me. Linux Ubuntu 20.04.4 LTS
Step 1:
Step 2:
Step 3:
Step 4:
Ready!!
For me it was the system language on Windows, I have changed it to English and it worked.
TL; DR
Make sure:
Your user has write permission into Android SDK directory.
ANDROID_HOME is correctly defined with the correct SDK location.
Description
IMHO it is a really bad practice install SDK into user home directory because:
Packages added will be restricted to a single user.
System administrators won't be able to mirror OS images, thus each engineer will have to install SDK manually.
The old school way is according to Linux directory hierarchy as described at The Linux Documentation Project, which consists on:
Ensure your user has adm privileges
Export SDK environment variables
Obey the filesystem hierarchy, installing the IDE and SDK into /opt
The steps above work perfectly on Ubuntu 22.04 and shall work on other distros with minor adjustments.
1. Ensure your user has adm privileges
grep adm /etc/group | grep ${USER}
adm:x:4:syslog,ventura
lpadmin:x:122:ventura
2. Configure environment variables
/etc/profile.d/
├── ...
├── android.sh
├── ...
├── java.sh
└── ...
where android.sh contains
#!/usr/bin/env bash
export ANDROID_HOME=/opt/google/android/
export FLUTTER_HOME=${ANDROID_HOME}/flutter
TOOLS=${ANDROID_HOME}/platform-tools
TOOLS=${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/tools:${TOOLS}
export PATH=${FLUTTER_HOME}/bin:${TOOLS}:${PATH}
and java.sh your JRE directory
#!/usr/bin/env bash
export JAVA_HOME=/usr/lib/jvm/java-18-openjdk-amd64
3. Install Android Studio and Android SDK
Download latest Android Studio and unpack it into /opt/jetbrains/:
VERSION=2021.2.1.16
sudo mkdir -p /opt/google/android
sudo mkdir -p /opt/jetbrains/studio
# Unpack Android Studio into a versioned folder
tar -xvzf android-studio-${VERSION}-linux.tar.gz
sudo mv android-studio /opt/jetbrains/studio/${VERSION}
# Grant write permission to administrators
sudo chown root:adm -R /opt/jetbrains/
sudo chmod g+w -R /opt/jetbrains/
sudo chown root:adm -R /opt/google/android
sudo chmod g+w -R /opt/google/android
Finally launch Android Studio and choose the SDK location:
This approach is extremely powerful because it allows system administrators duplicate development workstations using rsync -avz without relying onto any username or custom privileges.
I searched for many hours for an answer to this
I reinstalled:
I opened a new folder called Android in C:
Into it I reinstalled the android studio
You have created a new SDK folder within it
Then in the blank path, I entered C: \ Android \ sdk
And that's how it all worked.
Try it!
You can clear invalidate caches and restart android studio like follow picture:
Then start download sdk files :)
Make sure that your internet is working and try to close VPN connections if you have any. Then restart Android Studio and hope for the best.
To solve this issue, I had to close Android studio entirely. When I started the application again, it detected that it had a missing SDK problem and then went ahead with the installation process for it.
Your country should not be among the sanctioned countries (using VPN).
Android Studio by Run as Administrator open.
Download : Android SDK and Android SDK Platform.
Fix error: the android sdk location cannot be at the filesystem root.
For test The VPN is working properly.
Open website : https://developer.android.com/
this is the best solution to this error which is just under any drive you have on your laptop which C:// open a folder called "Android" and under the android folder open a folder called "sdk" and change the sdk file path to this recently created folder. That's All.
I built my project using the new Android App Bundle format. With APK files, I can download the APK to my device, open it, and immediately install the app. I downloaded my app as a bundle (.aab format) and my Nexus 5X running Android 8.1 can't open the file. Is there any way to install AABs on devices in the same convenient manner as APKs?
Short answer:
Not directly.
Longer answer:
Android App Bundles is the default publishing format for apps on the Google Play Store. But Android devices require .apk files to install applications.
The Play Store or any other source that you're installing from will extract apks from the bundle, sign each one and then install them specific to the target device.
The conversion from .aab to .apk is done via bundletool.
You can use Internal App Sharing to upload a debuggable build of your app to the Play Store and share it with testers.
For MAC:
brew install bundletool
bundletool build-apks --bundle=app-release.aab --output=app-release.apks
bundletool install-apks --apks=app-release.apks
Installing the aab directly from the device, I couldn't find a way for that.
But there is a way to install it through your command line using the following documentation You can install apk to a device through BundleTool
According to "#Albert Vila Calvo" comment he noted that to install bundletools using HomeBrew use brew install bundletool
You can now install extract apks from aab file and install it to a device
Extracting apk files from through the next command
java -jar bundletool-all-0.3.3.jar build-apks --bundle=bundle.aab --output=app.apks --ks=my-release-key.keystore --ks-key-alias=alias --ks-pass=pass:password
Arguments:
--bundle -> Android Bundle .aab file
--output -> Destination and file name for the generated apk file
--ks -> Keystore file used to generate the Android Bundle
--ks-key-alias -> Alias for keystore file
--ks-pass -> Password for Alias file (Please note the 'pass' prefix before password value)
Then you will have a file with extension .apks
So now you need to install it to a device
java -jar bundletool-all-0.6.0.jar install-apks --adb=/android-sdk/platform-tools/adb --apks=app.apks
Arguments:
--adb -> Path to adb file
--apks -> Apks file need to be installed
If you want to install apk from your aab to your device for testing purpose then you need to edit the configuration before running it on the connected device.
Go to Edit Configurations
Select the Deploy dropdown and change it from "Default apk" to "APK from app bundle".
Apply the changes and then run it on the device connected. Build time will increase after making this change.
This will install an apk directly on the device connected from the aab.
You cannot install app bundle [NAME].aab directly to android device because it is publishing format, but there is way to extract the required apk from bundle and install it to you device, the process is as follow
Download bundletool from here
run this in your terminal,
java -jar bundletool.jar build-apks --bundle=bundleapp.aab --output=out_bundle_archive_set.apks
Last step will generate a file named as out_bundle_archive_set.apks, just rename it to out_bundle_archive_set.zip and extract the zip file, jump into the folder out_bundle_archive_set > standalones, where you will seee a list of all the apks
There goes the reference from android developers for bundle tools link
For those, who want single universal.apk that can run on every android device:
brew install bundletool
bundletool build-apks --mode universal --bundle ./app-release.aab --output ./app.apks
mv app.apks app.zip
unzip app.zip
Now, you can get your universal.apk
This worked for me on a mac.
You need to use a tool called bundletool You can install it incase if not already installed using brew
brew install bundletool
Run this command to extract and store the apks file at the desired location
bundletool build-apks --bundle=path/to/app-release.aab --output=/path/to/output/app.apks --local-testing
Install on a connected Android device
bundletool install-apks --apks=/path/to/output/app.apks
I have noted the complete command with output in a gist here https://gist.github.com/maheshmnj/6f5debbfae2b8183d94ca789d081f026
If you're using Maui at this point Visual Studio 2022 only creates AAB files; however, you can create an APK from a command line.
Change directory to where your project is located and run this:
dotnet publish -f:net6.0-android -c:Release /p:AndroidSigningKeyPass=blah
If you want to install the APP bundle without using PLAY STORE, You need to change your build variant to "release" at Android studio.
If you cannot build App yourself but have a release bundle, then refer to the most popular answer.
Go to Android Studio > Build > Select Build Variant..
Once you do this your build configuration may start showing errors.
This is because you now need to provide signing details in this configuration as well (this refers signing details from build.gradle)
you may either Edit the configuration and go to the Fix button at the bottom which will ask you to fill in signing details.
Or you may edit the build.gradle
Make sure you provide buildTypes {} and signingConfigs {}
android {
signingConfigs {
release {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
debug {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
}
compileSdkVersion 32
defaultConfig {
....
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug
{
signingConfig signingConfigs.debug
}
}
...
}
dependencies {
...
}
There is one or two minutes of delay before Android Studio starts reflecting correctly. Otherwise, you may do a clean rebuild and then run the app.
When you run the app this time it will be installed in release mode on the target device.
You may need a way to identify the Build Variant of the installed app. You may show the build name and variant somewhere in your app. Or if you have a button somewhere which shows only in debug mode you can check that.
If you have the project you can just build an app with android studio or push it directly to the device if you run a debug or release config with the device connected and selected as the target so long as you enable adb in developer mode on the device and tap trust this computer when you connect it to your machine.
But if you have the bundle because you're trying to install an app pulled from one phone onto another, there are free online services that convert play store links into a direct download of the apk. Just turn on add debugging on the device and adb install <path-to-apk> from the terminal.
If you have more than one device connected with adb enabled you can adb devices to get a list of their identifiers and adb install <path-to-apk> <device-id> will work as well. Or you can use adb to your advantage and do many things on multiple devices at once depending on your needs. There's even ways to adb over wifi.
You will need adb from the android-sdk tools to do any of this though, with Android Studio installed you would have a local installation already but it may not be in your path. However studios terminal likely has access to it since it would be the sdk path your IDE has saved in preferences.. If not you can download a standalone sdk/find out which one studio is using from it's preferences and either
Add adb from the platform-tools directory of said sdk it to your path (best)
Invoke adb from it's absolute path you just located and just keep hitting up to re-use your last command, swapping out the apk/device
cd to the adb directory and just use it with the full path to each of your apks (easiest)
For Windows 11:
PS C:/folder-with-aab-file> java -jar C:\dev\bundletool-all-1.9.1\bundletool.jar build-apks --bundle=app-release.aab --output=app-release.aab.apks --mode=universal
PS C:/folder-with-aab-file> ren app-release.aab.apks app-release.aab.apks.zip
After descompact zip file, the apk file'll with the name: universal.apk
Is there any way to install AABs on devices in the same convenient manner as APKs?
As installing is done by third party apps or mobile company file manager like apps.
The upcoming file managers versions, hence forth, will come with "aab" managing tools.
I searched "android aab installer" on playstore and found one.
deliberately not naming it.
The one I installed, extracted the bundle online,
But after that this app wasn't able to install this extracted app by itself (on my mi [miui] device ).
But this application saved the online extracted apk on phone memory, from where I was able to install it.
remember:
Google's "files" application wasn't able to install this apkbutmy system (in built) filer manager was able to.
Use (on Linux):
cd android
./gradlew assemblyRelease|assemblyDebug
An unsigned APK is generated for each case (for debug or testing)
NOTE: On Windows, replace gradle executable for gradlew.bat
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!
I have been sent an android app to test. I saved the apk to my desktop, but now I don't know what else to do. How do I import it into androis studio? I know this is a very basic question but please be detailed, thank you.
Connect your android device (or start an emulator), go to the command prompt, change directory to where the apk is, and enter adb install apkname
Please follow the below steps to install apk file.
1.First run the emulator.
2. open the sdk specified path and find the platform tools folder.then copy the apk file and store it inside the platform-tools folder.(G:android-sdks\platform-tools).
3.open the command prompt and change the directory to android-sdks/platform tools.
4.enter the command : adb install apkfile name.
5.if you are getting success in command prompt the apk was sucessfully installed in your emulator..