Install Google Apps on AOSP Build

shlatchz picture shlatchz · Jan 17, 2017 · Viewed 18.4k times · Source

I have installed android-6.0.1_r72 AOSP Rom on a Nexus 5 device. The rom doesn't come with Google Apps.

I've tried to install from the following site, but after the installation I get

Unfortunately, Google Play services has stopped

Is there a special version of Google Apps that I have to install?

UPDATE:

I found this error in logcat:

01-17 11:14:52.750 3525 5402 E AndroidRuntime: FATAL EXCEPTION: GoogleLocationService

01-17 11:14:52.750 3525 5402 E AndroidRuntime: Process: com.google.android.gms.persistent, PID: 3525

01-17 11:14:52.750 3525 5402 E AndroidRuntime: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1620)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1573)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at android.location.ILocationManager$Stub$Proxy.addGpsStatusListener(ILocationManager.java:741)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at android.location.LocationManager.addGpsStatusListener(LocationManager.java:1522)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at aker.a(:com.google.android.gms:1064)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at akbc.b(:com.google.android.gms:6342)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at akbc.handleMessage(:com.google.android.gms:279)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148)

01-17 11:14:52.750 3525 5402 E AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:61)

UPDATE #2:

I still get the error, so I've opened an issue in the GApps git.

Answer

andDevW picture andDevW · Jan 24, 2017

Three things you are doing wrong:
1. You generally need to install APK pulled from the same version of Android that you want to run.
2. Don't ever download Google APK from non-Google sites.
3. In order to install system apps you need to first remount the system partition as read-write.

Here's how to get and then install genuine Google APK as system apps:

USE YOUR AOSP BUILD NUMBER TO GET THE MATCHING FACTORY IMAGE
The link you provided for AOSP Codenames, Tags, and Build Numbers has build numbers that you need to match. Search the page for android-6.0.1_r72 and the corresponding build number is M4B30X.

Instead of using untrusted APK from random sites (a terrible idea) you can obtain genuine APK directly from the good folks at Google with the help of their Factory Images. Search the page for your build number M4B30X and download the image. Next, cd into the folder where you downloaded the image and run a check on the SHA-256 Checksum:

$ cd Downloads

$ echo "10cfaa5c8ff1753af20283f5e5f938ddebbad094c4e22aadbd925ecdc806e8b3   
  hammerhead-m4b30x-factory-10cfaa5c.zip" | sha256sum -c

It should print: hammerhead-m4b30x-factory-10cfaa5c.zip: OK
-If not, download the image again.

FLASH FACTORY IMAGE AND PULL GENUINE GOOGLE APK
1. Flash the Factory Image and boot into the system.
2. Activate Developer options and allow 'USB Debugging'
3. Now use ADB to pull(get) the 100% genuine Google Play APK:

$ adb pull /system/priv-app/GoogleServicesFramework/GoogleServicesFramework.apk
$ adb pull /system/priv-app/Phonesky/Phonesky.apk
$ adb pull /system/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk

FLASH AOSP HAMMERHEAD M4B30X AND PUSH GENUINE GOOGLE APK
Make sure that you flash either the userdebug or eng variant.

Push APK files to your sdcard:

$ adb push GoogleServicesFramework.apk /sdcard/
$ adb push Phonesky.apk /sdcard/
$ adb push PrebuiltGmsCore.apk /sdcard/

MANUALLY INSTALL APK AS SYSTEM APPS

$ sudo adb shell

Locate system partition: root@hammerhead:/ # mount | grep "/system" You should get back: /dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,seclabel,relatime,data=ordered 0 0

Now mount that system partition as rw(read-write)

root@hammerhead:/ # mount -o remount,rw -t ext4 /dev/block/platform/msm_sdcc.1/by-name/system /system 

root@hammerhead:/ # cd /system/priv-app   
root@hammerhead:/ # mkdir GoogleServicesFramework
root@hammerhead:/ # mkdir Phonesky
root@hammerhead:/ # mkdir PrebuiltGmsCore

root@hammerhead:/ # cp /sdcard/GoogleServicesFramework.apk GoogleServicesFramework/GoogleServicesFramework.apk
root@hammerhead:/ # cp /sdcard/Phonesky.apk Phonesky/Phonesky.apk
root@hammerhead:/ # cp /sdcard/PrebuiltGmsCore.apk PrebuiltGmsCore/PrebuiltGmsCore.apk

root@hammerhead:/ # chmod 755 GoogleServicesFramework
root@hammerhead:/ # chmod 755 Phonesky
root@hammerhead:/ # chmod 755 PrebuiltGmsCore

root@hammerhead:/ # chmod 644 GoogleServicesFramework/GoogleServicesFramework.apk
root@hammerhead:/ # chmod 644 Phonesky/Phonesky.apk
root@hammerhead:/ # chmod 644 PrebuiltGmsCore/PrebuiltGmsCore.apk

CONFIGURE AOSP

Grant Google Apps Permissions
On your phone, go into Settings>Apps In the overflow menu (gear button upper right corner)
Select Show system
Navigate down to Google Play Store and allow it all of the permissions.
Do the same for Google Services Framework and Google Play Services (PrebuiltGmsCore).
Now make sure ALL of the default AOSP apps have their respective permissions granted.
AOSP by default comes with many permissions turned off.
Allow ALL permissions for the following apps:
Android Keyboard
Browser
Calendar
Camera
Clock
Contacts
Email
Gallery
Launcher3
Messaging
Music
Phone

*And the ever-janky looking Search, if for some reason you don't want to disable it.

Now make sure that Wifi is connected and/or your SIM card is in and providing signal.
Reboot.
You should have some brief errors as everything gets sorted, although if the errors continue, another reboot should fix it.