anbox / anbox

Anbox is a container-based approach to boot a full Android system on a regular GNU/Linux system
https://anbox.io
GNU General Public License v3.0
8.9k stars 1.16k forks source link

Root permission for apps #118

Closed daryl0 closed 5 years ago

daryl0 commented 7 years ago

I want install gapps from apk. For install it is necessary root permission.

With command adb shell and then SU I Take root permission but I stop it.

Help me.

dispicio commented 7 years ago

We need to modify android.img for this. Extract the image (sudo to preserve permission/owner/groups): sudo unsquashfs android.img Then make your desired modifications (like cp su to /system/bin. Mind permissions/owner/groups of the new files). Finally "repack" the image: mksquashfs squashfs-root android.img -b 131072 -comp xz -Xbcj x86

Get the Google apps here (cp to /var/lib/anbox/rootfs/system/app): http://opengapps.org/ Latest SuperSU-zip (cp to /var/lib/anbox/rootfs/system/bin): http://www.supersu.com/download

I haven't been able to get GApps running though.. 😒 Maybe someone else is luckier?

daryl0 commented 7 years ago

android image (android.img) I found in /snap/anbox/current ?

cd /snap/anbox/current and then you command? sudo unsquashfs android.img and then repack android image is ok?

daryl0 commented 7 years ago

I try Extract android.img from /snap/anbox/current but it is read only.

I download android.img from here (http://build.anbox.io/android-images/2017/04/12/android_1_amd64.img) Then i follow you command:

I try it and report here result.

subjectdenied commented 7 years ago

everytime i tried to change something in the unsquashed image, after squashing it again, the image is running for me. however adb won't see the emulator device anymore

morphis commented 7 years ago

@subjectdenied the ADB connection is a bit flawky. Something we should rework. Can you open a separate issue for that?

dispicio commented 7 years ago

Another try. Got play store starting, but as there is no network connection (another problem #51), it's pretty useless. I did not get root working! (tried to put su in /system/xbin with suid and symlink it from /system/bin). Anyhow, here's what I did for the play store:

  1. sudo unsquashfs android.img
  2. Download & extract http://opengapps.org/ (x86_64, 7.1, mini)
  3. Extract Core/vending-all.tar.lz, Core/gsflogin-all.tar.lz, Core/gsfcore-all.tar.lz, Core/gmscore-x86_64.tar.lz
  4. Find and copy the folders Phonesky, GoogleLoginService, GoogleServicesFramework, PrebuiltGmsCore you extracted in 3. to squashfs-root/system/priv-app/
  5. sudo chown -R 100000:100000 Phonesky GoogleLoginService GoogleServicesFramework PrebuiltGmsCore inside squashfs-root/system/priv-app
  6. sudo mksquashfs squashfs-root android.img -b 131072 -comp xz -Xbcj x86

[Edit: Got network running after installing dnsmasq and getting anbox-bridge.sh from this repo. sudo ./anbox-bridge.sh start. On Arch Linux] [Edit 2: Google Play Store launches, I'm able to login. There are no apps available though, now fiddling with system/build.prop.] [Edit 3: Has anyone a x86 chromebook and is willing to provide its build.prop?]

subjectdenied commented 7 years ago

@dispicio : session-manager is crashing for me after using the image modified as you explain, also the new image is 4x the size of the original one

dispicio commented 7 years ago

I guess the crashing is normal; this software is pre-alpha. You can try to fiddle around with the -comp compression parameters in mksquashfs in order to make the image smaller (I get a roughly 15% bigger image than the original though, not 4x).

subjectdenied commented 7 years ago

@dispicio : size was my fault, crash is gone too. seems like the "device" is configured for tablets only. i see some new apps, also can see some i own

daryl0 commented 7 years ago

@dispicio sorry I am exhausted. Kindly write me exactly all the steps, but especially the working directory in question as well as at the controls? On Linux I work with Android but I have a lot of practice.

Thanks and excuse me. :-(

oleid commented 7 years ago

@dispicio Thanks for letting me know how to get PlayStore working.

FYI: I had a little trouble getting DNS working in the container (pinging was successfully tested via adb shell ). The anbox-bridge.sh script didn't work for me, however specifying a DNS server in /usr/lib/systemd/network/80-anbox-bridge.network successfully passed it down to the container.

The only problem now is that phone-only apps like Threema, WhatsApp or TomTom Go are not installable since my device isn't compatible with this version -- according to PlayStore.

asharptech commented 7 years ago

@oleid install them from apkmirror.com ?

oleid commented 7 years ago

Thanks for the hint. It would seem, as if the TomTom app is only available for ARM. That's a pity. I guess one would have to hook up the runtime with qemu, as they did with the ASUS Zenphone.

ghost commented 7 years ago

@dispicio After step 6, where do i save generated android.img file?

ghost commented 7 years ago

dear @dispicio

thanks a lot, your tip worked. But I had to change the google service and play store in [settins / apps] permissions, granting these apps all permissions. I did not need to change the build.prop

[Edit 2: Google Play Store launches, I'm able to login. There are no apps available though, now fiddling with system/build.prop.]

markmcwong commented 7 years ago

Hi I followed the step by dispicio and unsquashfs the android.img, I also extracted those 4 folders in the correct place and i sudo chown them and squashing them again. Then I use sudo anbox container-manager --android-image=/home/mark/anbox-work/anbox/android.img --data-path=/home/mark/anbox-data and restart my computer.

I tried to use playstore it opens and close immediately (youtube requires google play services), any suggestion? (Is su necessary in this case?)

ghost commented 7 years ago

Have you ever tried to change the permissions of google play store? Go in settings-->apps-->play store and choose permissions to play store.

markmcwong commented 7 years ago

I allow all permissions for play store and allows modify system settings but still no luck

ghost commented 7 years ago

@markmcwong You have to do the same with google play service.

ex

markmcwong commented 7 years ago

@gilzamir thank you for your help, it works and now youtube wont ask for google play framework and play store doesnt close after open but playstore just remain as a blank screen and when I clear data/cache and restart it spinner appears for like 5s and disappear and remain blank screen

subjectdenied commented 7 years ago

@gilzamir : do you see all play store apps, or just a fraction of it? cause when i tried this days ago, i only saw about 4 apps available, that i didn't have installed yet on any of my devices before. i could get more apps shown by changing system/build.props, however never got the same pool as my phone would give me

markmcwong commented 7 years ago

@subjectdenied I cant see any play store apps as it remains a white blank screen. I researched about the problem as people suggested to clear cache and data + remove google account

However when I tried to add my Google Account in Settings > Account it just close immediately

ghost commented 7 years ago

@subjectdenied @markmcwong I can see a few apps. It must be because the image android.img architecture is x86 and most of the apps just support arm. In addition, the build.prop file does not seem to be well configured. You can solve some of the problem by changing the build.prop file.

I've downloaded several apps from the appmirror site and they're working fine.

image

I can not find youtube, but I can grab a few apps.

image

ghost commented 7 years ago

Dear, the internet is necessary for the play store works. Run the following command to internet to work in the container

sudo /snap/anbox/current/bin/anbox-bridge.sh start

ktp420 commented 7 years ago

Anyone here build an arm android image and got arm apps running inside it?

seanlano commented 7 years ago

@ktp420 that would require an ARM CPU. Anbox doesn't emulate a CPU, it uses the host computer hardware.

ktp420 commented 7 years ago

Yes I know but was just wondering if something tried it

ghost commented 7 years ago

@ktp420 It may be more helpful to try to get a image of the AndroidX86 project. I think AndroidX86 has arm support, even though it's x86.

ktp420 commented 7 years ago

I build the arm image for sources...just didn't want to download 40 gb if didn't need to.

virajmalia-zz commented 7 years ago

@gilzamir Where did you save the squashed image?

Edit: Got it working. For future visitors, https://github.com/anbox/anbox/blob/master/docs/build-android.md

sjodiel commented 7 years ago

How can I replace the android.img for my android.img modified?

tbraeutigam commented 7 years ago

Did anyone get the ARM binary support working? I wasn't able to get houdini to work seeing how I couldn't register anything in binfmt in the container. If someone managed -- do you have a guide? Or a working image to share?

krzys-h commented 7 years ago

The reason almost no apps appear in the play store is that Anbox by default doesn't report almost any features, not even the ones that are often declared implicitly like android.hardware.touchscreen. You can see what features the device reports as available using adb shell pm list features. I managed to get almost all apps to appear with the following changes:

diff -ruN squashfs-root/system/build.prop squashfs-root-modified/system/build.prop
--- squashfs-root/system/build.prop 2017-07-13 13:01:38.000000000 +0200
+++ squashfs-root-modified/system/build.prop    2017-07-26 23:32:34.517463493 +0200
@@ -26,8 +26,8 @@
 # ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,
 # use ro.product.cpu.abilist instead.
 ro.product.cpu.abi=x86_64
-ro.product.cpu.abilist=x86_64,x86
-ro.product.cpu.abilist32=x86
+ro.product.cpu.abilist=x86_64,x86,armeabi-v7a,armeabi
+ro.product.cpu.abilist32=x86,armeabi-v7a,armeabi
 ro.product.cpu.abilist64=x86_64
 ro.product.manufacturer=unknown
 ro.product.locale=en-US
@@ -71,3 +71,7 @@
 dalvik.vm.lockprof.threshold=500
 net.bt.name=Android
 dalvik.vm.stack-trace-file=/data/anr/traces.txt
+
+# Report GLES as available
+# 131072 ix 0x20000 in hex, which means GLES 2.0
+ro.opengles.version=131072
diff -ruN squashfs-root/system/etc/permissions/anbox.xml squashfs-root-modified/system/etc/permissions/anbox.xml
--- squashfs-root/system/etc/permissions/anbox.xml  2017-07-13 13:19:19.000000000 +0200
+++ squashfs-root-modified/system/etc/permissions/anbox.xml 2017-07-26 23:32:51.737464010 +0200
@@ -17,6 +17,19 @@
 <permissions>
     <feature name="android.software.freeform_window_management" />
     <feature name="android.hardware.ethernet" />
+
+   <feature name="android.hardware.touchscreen" />
+   <feature name="android.hardware.audio.output" />
+   <feature name="android.hardware.camera" />
+   <feature name="android.hardware.camera.any" />
+   <feature name="android.hardware.location" />
+   <feature name="android.hardware.location.gps" />
+   <feature name="android.hardware.location.network" />
+   <feature name="android.hardware.microphone" />
+   <feature name="android.hardware.screen.portrait" />
+   <feature name="android.hardware.screen.landscape" />
+   <feature name="android.hardware.wifi" />
+   <feature name="android.hardware.bluetooth" />

     <!-- Disallow device admin and profile owner on Anbox-->
     <unavailable-feature name="android.software.device_admin" />
@@ -25,8 +38,8 @@
     <!-- Disable support for hardware we don't support -->
     <unavailable-feature name="android.hardware.usb.accessory" />
     <unavailable-feature name="android.hardware.usb.host" />
-    <unavailable-feature name="android.hardware.wifi" />
-    <unavailable-feature name="android.hardware.bluetooth" />
+    <!--<unavailable-feature name="android.hardware.wifi" />-->
+    <!--<unavailable-feature name="android.hardware.bluetooth" />-->
     <unavailable-feature name="android.hardware.bluetooth_le" />
     <unavailable-feature name="android.hardware.sensor.compass" />
     <unavailable-feature name="android.hardware.sensor.accelerometer" />

I also made it display arm apps because I was trying to get libhoudini to work. Note that google play seems to cache this data somewhere, so every time you change these files and rebuild android.img you have to go to app settings and clear its data.

Unfortunately most apps I tried to run don't work because they either don't support android.software.freeform_window_management or - even worse - try to force the device into portrait mode.

geeks-r-us commented 7 years ago

Hey I made a little wrap up how to get PlayStore working. It's a german post but google translate is your friend: http://geeks-r-us.de/2017/08/26/android-apps-auf-dem-linux-desktop/

morphis commented 7 years ago

@geeks-r-us That is great! Can you create PRs to get the missing features in the .xml files added? See https://github.com/anbox/device_anbox/blob/master/anbox.xml for a place to do that

geeks-r-us commented 7 years ago

I can do this. But I do not know if this will work or not haven't tested apps with bt for example...

eugenio commented 7 years ago

@geeks-r-us, I followed the procedure you are listing in the blog post above ~~but after I resquash and put the image into place the anbox doesn't start anymore... It just gives the starting screen and then it closes it after a while.~~ EDIT: I was able to start anbox after some fiddling around with androids build.prop and anbox.xml . The playstore works and I was able to install a few apps but none of them worked... This is probably because my anbox build is not the offical one(I am using debian) but an old build packaged for debian by another debian user, and anbox itself is still alpha software stage... I have a question though: how can I be certain that libhoudini is working?

sayeed99 commented 7 years ago

@eugenio libhoudini is selected natively by the framework depending on how the app wants us to use it. OEMs using x86 follow a rather amazing way to get this sorted (got no idea about it). But I guess we can do something like we did on zenfone 2(intel x86) https://review.lineageos.org/#/c/66695/ to force picking of libs.

step21 commented 6 years ago

Generally it works for me, but when logging in and the accepting the terms & conditions, it says to try again later. (after 2 factor authentication worked) Anybody know why or how to get some debug output?

ShankarVibhuti commented 6 years ago

sudo anbox container-manager --data-path=~/anbox-data --android-image=~/anbox-work/android.img This command insn't working for me and the /snap/anbox/current/android.img file is read only for me.

step21 commented 6 years ago

Unmount the snap. Unpack it with squashfs. Replace the android.img there with the new one. Pack it back together. You cannot write to snaps directly afaik. There is a blog post somewhere about it.

ShankarVibhuti commented 6 years ago

How to unmount the snap folder? Normal unmount command is not working. It returns mount: can't find /snap in /etc/fstab @step21

step21 commented 6 years ago

It should work. It is not supposed to be in /etc/fstab Maybe make sure anbox is stopped and snap disabled first. Blog post http://geeks-r-us.de/2017/08/26/android-apps-auf-dem-linux-desktop/ (use google translate) Comments are especially important.

ShankarVibhuti commented 6 years ago

Hey! @step21 I finally managed to complete this task. But now when I open Google Play Store it says, " Trouble connecting to server". The Internet doesn't seem to work in any app inside anbox. sudo /snap/anbox/current/bin/anbox-bridge.sh start anbox-bridge is already running

ShankarVibhuti commented 6 years ago

anbox0 Link encap:Ethernet HWaddr fe:5c:e4:cc:14:a7 inet addr:192.168.250.1 Bcast:0.0.0.0 Mask:255.255.255.0 inet6 addr: fe80::24a2:7ff:fec1:efeb/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:19 errors:0 dropped:0 overruns:0 frame:0 TX packets:115 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1256 (1.2 KB) TX bytes:14774 (14.7 KB)

geeks-r-us commented 6 years ago

@VieSel I updated the post with more bug fixing for connection issues.

And also added an initial version of an install script that adds ARM translation and Play Store to the Anbox image automatically

lemrm commented 6 years ago

@step21

Unmount the snap ... Replace the android.img there with the new one

How to do this? I can't get it.

Rehazen commented 6 years ago

@geeks-r-us i just literally start using linux 3 days ago, what must i do with script step by step in your blog? copy-paste in terminal? something i did is copying your full script, and try to run in terminal, after that my anbox just in the "starting" screen (can't go in menu)

datamaskinen commented 6 years ago

it would be good if someone could put up a done .img file on github instead maybe

shawe commented 6 years ago

@step21 Your external link works for me. This page contains this script https://github.com/geeks-r-us/anbox-playstore-installer/raw/master/install-playstore.sh

On Antergos I need to replace line 106, with cp /var/lib/anbox/android.img . And from line 203 to the end with (this part seems to be very different):

#cd /var/lib/snapd/snaps
cp $WORKDIR/android.img /var/lib/anbox/android.img
$SUDO systemctl restart anbox-container-manager.service

Not works perfect, but is a step closer. Maybe as @morphis say, is needed a beeter https://github.com/anbox/device_anbox/blob/master/anbox.xml