cannot change file permissions on Android Virtual Device (AVD) - android

I am unable to change permissions on a shell script I need to test on an Android Virtual Device (AVD). The AVD is Google Pixel 2 (API 29) - it was created via Android Studio. Using Android Debug Bridge (adb) from Android SDK on a MacBook, I did:
%adb push file.sh /sdcard/steve
The file.sh script is executable (mode 755) on the MacBook, but when it gets pushed onto the AVD, the mode goes to 660 (i.e. no longer executable). So then I do:
%adb shell
which opens up an emulator shell session. I then proceed in the AVD shell session as follows:
%generic_x86: cd /sdcard/steve
%generic_x86: chmod +x file.sh
This yields no error message and actually no message at all. There is no change to the permissions for file.sh. It remains not executable. Do I need to push the file to a different directory on the AVD? Or is there some other way to make me able to change file permissions once it is pushed onto the AVD (emulator)? Note: I have looked at the Android Studio "Device File Explorer" where one can create files and directories on the AVD, however, one cannot change permissions on the files. TIA for any tips,Steve

OK - I seemed to have solved this via what I would call circuitous means. As mentioned earlier, I can push a file to my AVD via:
%adb push file.sh /sdcard/steve
The problem was then I could not change permissions on this file. I found out the command "run-as (classname)" gave me the ability to do a chmod. So the sequence is this:
%adb push file.sh /sdcard/steve
%generic_x86:run-as com.example.helloworld
%generic_x86:cd /data/data/com.example.helloworld
%generic_x86:mkdir steve
%generic_x86:cd steve
%generic_x86:cp /sdcard/steve/file.sh .
%generic_x86:chmod +x file.sh
Now I'm off to the races. Interestingly, the one location on the AVD I can push files to is /sdcard. Thanks to "blackapps" for your inputs.

Related

Update AOSP built-in system app

Lets say we have downloaded, built and flashed AOSP source code. Now a change to a system app is made (e.g. changed a constant in the packages/apps/Nfc package).
The next step is to build it, and there are two ways to do it:
cd packages/apps/Nfc; mm
or
mmm Nfc
This will create out/target/product//system/app/NfcNci/NfcNci.apk file
Which is the proper way to update the system app?
I tried using adb install NfcNci.apk but no success:
~/android/aosp-7.1.2-3.10-v2/out/target/product/kugo/system/app/NfcNci$ adb install NfcNci.apk
Failed to install NfcNci.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install com.android.nfcnci without first uninstalling.]
~/android/aosp-7.1.2-3.10-v2/out/target/product/kugo/system/app/NfcNci$ adb install -r NfcNci.apk
Failed to install NfcNci.apk: Failure [INSTALL_FAILED_INVALID_APK: Package couldn't be installed in /data/app/com.android.nfcnci-1: Package /data/app/com.android.nfcnci-1/base.apk code is missing]
Found a way to easily 're-install' the app itself (let's put Settings app as an example):
mmm packages/apps/Settings # Build the module
adb root ; adb remount # Restart adbd as root and mount /system as writable
adb push out/target/product/<device_name>/system/priv-app/Settings /system/priv-app # Push the built files to the device
Then force-close and restart the app (by swiping it from Recents). No need to reboot device in order to take changes
NOTE: Depending on the app, the path may be on system/app instead of /system/priv-app
Another way is to:
copy the new apk to the sdcard of the device with adb push
mount /system read write: mount -o rw,remount,rw /system
copy your new .apk from /sdcard over your old .apk in /system/app
remove the .odex file of your old .apk
reboot the device
For development you can use a simple script for this steps.
Check build/envsetup.sh file - there's also commands mmp and mmmp to build and push a module to connected device. Also adb sync can be used to sync whole image, so if you updated a module, changed files will be pushed to device.
Also you can put the changed files via regular `adb push' and reboot device.
I do not know if system apps can be updated via adb install, probably yes, but I think you need to increment build number in the manifest file.
I do not think you can uninstall a system app with adb install -r, as apps can't be removed from system partition, only from data. I do not know why you are getting INSTALL_FAILED_INVALID_APK in that case, may be because app manager can't uninstall the base system apk indeed.

Installing Android System-App on Emulator does not work

I have a System App that is capable of performing some system level tasks (Ex: remote reboot etc.). I want to try this out in the Android-Dev-Studio Emulator.
I have googled for it and this is what I've found so far:
Build the .apk
adb remount
adb push [MyApp.apk] /system/app/ (this is /system/priv-app in API Level 19+)
adb shell chmod 644 /system/app/[MyApp.apk]
adb reboot
I have done all of this. I've tried copying my apk to both folders "/system/app/" and "/system/priv-app/" folders. Regardless, when I reboot the emulator does not show anything and gets stuck.
According to this question reboot does not work for emulators which I also noticed to be correct, since the copied .apk file is lost upon restart.
What am I missing here?
I am compiling and building for SDKVersion - 21. So which folder should I copy my system app to? (/system/app/ or /system/priv-app)?
Also if reboot does not work for emulators, how do I get the app installed and running?
What's android version of your emulator?
The "/system/app/" and "/system/priv-app/" directory structure have been changed since Android L, you should use:
adb push MyApp.apk /system/priv-app/MyApp/

Android Studio - Android Device Monitor's File explorer not working

I have just learnt using preferences in Android. For debugging purpose I need to access the preferences files. I googled and found the default location of the preference file and also how to access it via Android Device Monitor.
Somehow I am not able to open any folders under the File explorer tab of the Android device monitor. They just aren't responding. I tried waiting for ADM to load and tried again but no success. (Double click on folder is not working, STRANGE!)
Do we need to configure before using it? I am using Android studio.
Any help would be appreciated.
Attaching image
Finally I found how to make it work.
goto run -> location where your adb is
Ex: C:\Program Files (x86)\Android\android-sdk\platform-tools
type adb root , Enter (Your phone must have root)
If this doesn't work, install this app on your phone: [root] adbd Insecure or its free alternative here (update: link broken now).
Get more info at http://forum.xda-developers.com/showthread.php?t=1687590
You will need either to use the emulator or to have a rooted phone to use all functionalities.
Root your device and open adb shell and change the permissions as:
$ adb shell
$ su
1|root#android:/ # chmod -R 777 data/

Android Studio pm install aborted

Im trying to run an application on my GS5 from android studio and Im getting this:
Waiting for device.
Target device: samsung-sm_g900v-f3af9744
Uploading file
local path: D:\Android\Projects\TestProject\build\outputs\apk\TestProject-debug.apk
remote path: /data/local/tmp/com.brian.testproject
Installing com.datascan.mobilescripts
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.brian.testproject"
Aborted
It seems to be copying the file to the device, I can see it in the /data/local/tmp directory. Its just failing at the "pm install" stage.
On the phone I turned on USB Debugging and authorized the computer. Here is what I get when I run ADB devices:
D:\Android\sdk\platform-tools>adb devices
List of devices attached
f3af9744 device
So that seems to be correct. Im not really sure what the problem is. Google search on the problem didnt give me any relevant results.
Does anyone know how to get more information beyond "Aborted"? Any help is appreciated, Thanks!
EDIT:
As suggested by #AlexP. I ran "adb logcat -d -s PackageManager:*", this was the result:
D:\Android\sdk\platform-tools>adb logcat -d -s PackageManager:*
--------- beginning of main
--------- beginning of system
Not much help, but I did decide to watch the logcat as the pm install was being run and I found this error entry:
Tag=appproc | Text= ERROR: Could not find class 'com.android.commands.pm.Pm'
Tag=art | Text= art.runtime/thread.cc:1105] No pending exeption expected: java.lang.ClassNotFoundException: Didn't find class "com.android.commands.pm.Pm" on path: DexPathList[[zip file "/system/framework/pm.jar"],nativeLibraryDirectories=]/vendor/lib, /system/lib]]
Followed by a whole slew of art error entries.
So it seems as though my phone is missing something, maybe?
The reason that Android Studio fails on Galaxy S5 is because the adbd (ADB service on the phone not your PC), on rooted version of this phone does not run as root, which is a security measure. You can verify this by manually trying to execute the Android Studio apk and execute commands on the device and finding out that they are failing to execute, but retrying them using "su ..." and see that the app installs and starts on the device. There are three options to resolve this and unblock Android Studio:
Options:
Flash a ROM that includes the modification - not desired as from my understanding you would like to stay on the stock image; also a good security measure not to have adbd running as root all the time. Older roms fall in this category as well, but then you are missing Stock Rom updates and security patches.
Create a custom boot.img and flash it to your phone - this is basically a custom kernel and not desired for a similar reasons than above option 1.
Restart adbd on your device with root privileges when doing app development - preferred and achievable fairly easy thru various methods including:
Preferred Solution:
a. Restart adbd with root privileges (insecure mode) by killing the service on the phone and using a terminal app or so to restart it using "su". After you are done with your app development, restart your phone and adbd will be back in secure mode, restoring the security measures.
b. Use Chainfire's ADB insecure app, which is free on XDA (download/link below) or pay for it on Google Play to support his work. You can toggle the mode in the app. In the app, you also have an option to auto re-enable the insecure mode on reboots.
References:
https://android.stackexchange.com/questions/5884/is-there-a-way-for-me-to-run-adb-shell-as-root-without-typing-in-su
http://forum.xda-developers.com/showthread.php?t=1687590 (includes free download link)
https://play.google.com/store/apps/details?id=eu.chainfire.adbd (for supporting Chainfire's work)
Possible Solutions :
1. Check if your app had left any datas :
First if the app is already installed, then clean cache data and uninstall it
Under "System Settings" then "Application Manager"
http://i.stack.imgur.com/b3oys.jpg
Then
Force uninstall by running & adb shell pm uninstall com.brian.testproject
Check "/data/data/com.brian.testproject/" and delete it
Remove any entries of your package on /data/system/packages.xml
Remove any entries of your package on /data/system/packages.list
Also you could install SDMaiD and clean your device, especially with "CorpseFinder" and "AppCleaner"
2. Try to install the app manually and debug the result :
In your case you have an issue with pm over android studio... install it manually to have a more detailed message over command line
$ adb push D:\Android\..\TestProject-debug.apk /sdcard/myapp.apk
$ adb shell pm install /sdcard/myapp.apk
3. Check Android Studio and your app sources
Change the targeted api level :
Right click on your app dir + Open Module Settings + app + check sdk version + change target and minimum under "Flavor"
Sync gradle button
Rebuild project
https://www.youtube.com/watch?v=v4b7C6Q-9dI
Update your android studio if you don't have the last release
If your app use libraries, you have to recompile them.
4. Check System Settings :
Check BOOTCLASSPATH of your init.rc. BOOTCLASSPATH must include /system/framework/ext.jar and /system/framework/framework.jar and so on.
Check DEXPREOPT_BOOT_JARS of build/core/dex_preopt.mk. DEXPREOPT_BOOT_JARS must include ext and framework and so on.
The order of all items on BOOTCLASSPATH must be equal to the order of all items on DEXPREOPT_BOOT_JARS.
5. Try pm command directly on the device :
if pm command does not work try that command with a terminal directly on the phone to see if it's a connection issue between pc and phone
pm install /sdcard/myapp.apk
6. Reinstall your rom once again (just reinstall it) no need to erase.
For anyone having this same issue, unfortunately the only solution that I could find was to downgrade my ROM version (to OA8). Once I did that, adb works perfectly. If anyone finds a better solution I'd be definitely like to know.
Android Studio
step 1: Go to file--> invalidate and restart.
step 2: Clean and rebuild project.
step 3: go to project folder run
gradle clean
step 4: restart phone/Emulator.
Done !!!

Android eclipse emulator: can't access data/app

I wanted to delete my custom apps on the Android emulator in Eclipse. I followed this guide and encountered the same behaviour as described in this question. I also tested the root access the same way Arsalan mentioned in his first answer and got the same result.
I would like to try if Vyomas approach works, but I don't know the command for deleting an app.
Can anyone help?
I am assuming you are getting "rm failed for minesweeper.apk, Read-only file system"
If that's the case, then you could always press "page up" to bring up the menu in the homescreen and uninstalled it through Settings -> applications -> Manage Applications
Or you could keep going comando style and use this from androidkit, worked for me:
Using adb shell :
Important: The device has to be unplugged from USB if you are trying to uninstall from the emulator, else emulator should not be open and device needs to be plugged in the USB of the PC if you are trying to uninstall from the G1 Device. If either of them are not connected the adb shell command will not work.
Go to the shell and making sure adb is in PATH:
Go to shell (from cmd->adb shell or directly through a terminal)
#
#cd data
#cd app
#cd ls
#rm com.company.product.apk
Can you not just reset the device on startup if you want it removed? If your using the Eclipse add-on to use the emulator just select the box to wipe user data before you launch?
Si

Categories

Resources