build android 10 with 8G ram laptop

you may encounter problem when building android with low ram machine

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.Arrays.copyOf(Arrays.java:3793)
at com.intellij.util.ArrayUtil.realloc(ArrayUtil.java:84)
at com.intellij.lang.impl.TokenSequence$Builder.resizeLexemes(TokenSequence.java:114)
at com.intellij.lang.impl.TokenSequence$Builder.performLexing(TokenSequence.java:77)
at com.intellij.lang.impl.PsiBuilderImpl.performLexing(PsiBuilderImpl.java:187)
at com.intellij.lang.impl.PsiBuilderImpl.(PsiBuilderImpl.java:160)
at com.intellij.lang.impl.PsiBuilderImpl.(PsiBuilderImpl.java:114)
at com.intellij.lang.impl.PsiBuilderFactoryImpl.createBuilder(PsiBuilderFactoryImpl.java:37)
at com.intellij.lang.java.parser.JavaParserUtil.createBuilder(JavaParserUtil.java:152)
at com.intellij.psi.impl.source.JavaFileElementType.parseContents(JavaFileElementType.java:80)
at com.intellij.psi.impl.source.tree.LazyParseableElement.lambda$ensureParsed$0(LazyParseableElement.java:189)
at com.intellij.psi.impl.source.tree.LazyParseableElement$$Lambda$217/0x0000000100515040.run(Unknown Source)
at com.intellij.psi.impl.DebugUtil.performPsiModification(DebugUtil.java:564)
at com.intellij.psi.impl.source.tree.LazyParseableElement.ensureParsed(LazyParseableElement.java:188)
at com.intellij.psi.impl.source.tree.LazyParseableElement.getFirstChildNode(LazyParseableElement.java:237)
at com.intellij.psi.impl.source.tree.CompositeElement.countChildren(CompositeElement.java:432)
at com.intellij.psi.impl.source.tree.CompositeElement.getChildrenAsPsiElements(CompositeElement.java:394)
at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.getClasses(PsiJavaFileBaseImpl.java:66)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl$Companion.findClassInPsiFile(KotlinCliJavaFileManagerImpl.kt:263)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl$Companion.access$findClassInPsiFile(KotlinCliJavaFileManagerImpl.kt:259)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl.findPsiClassInVirtualFile(KotlinCliJavaFileManagerImpl.kt:229)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl.findClass(KotlinCliJavaFileManagerImpl.kt:124)
at org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade$CliFinder.findClass(KotlinJavaPsiFacade.java:363)
at org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade.findClass(KotlinJavaPsiFacade.java:123)
at org.jetbrains.kotlin.load.java.JavaClassFinderImpl.findClass(JavaClassFinderImpl.kt:36)
at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope$classes$1.invoke(LazyJavaPackageScope.kt:76)
at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope$classes$1.invoke(LazyJavaPackageScope.kt:42)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:512)
at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope.findClassifier(LazyJavaPackageScope.kt:142)
at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope.getContributedClassifier(LazyJavaPackageScope.kt:132)
at org.jetbrains.kotlin.load.java.lazy.descriptors.JvmPackageScope.getContributedClassifier(JvmPackageScope.kt:52)
at org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope.getContributedClassifier(ChainedMemberScope.kt:33)

have a check for your build machine

java -XshowSettings 2>&1  | grep Heap

https://cs.android.com/android/platform/superproject/+/master:build/soong/java/config/config.go;l=64?q=build%2Fsoong%2Fjava%2Fconfig%2Fconfig.go

change this line from 2048 to 1024

pctx.StaticVariable("JavacHeapSize", "1024M")
android metalava use a lot of memory

 

or you can also try adjust linux memory setting

cat /proc/sys/vm/overcommit_ratio
cat /proc/sys/vm/overcommit_memory

 

But I still fail to build AOSP and seems adding swap has no help for java max heap size

refer: https://stackoverflow.com/a/34858395/1117177


Do. Not. Do this.

Get more memory.

Java and Swap Do. Not. Mix. Java and Swap are like "Crossing the Streams" Bad.

Part of the Java heap will be swapped out, then Java will GC, which will thrash the box terribly, and still part of the heap will be swapped out, and Java will GC again.

Rinse and repeat until you finally kill -9 Weblogic.

Get more memory, or do without. Swap is not an option.

Addenda:

You machine has "Virtual Memory" (VM). By adding swap, you extend that VM. When you have more VM than actual memory, then the machine will "swap out" inactive memory pages to the swap space, and then "swap in" pages that want to be active from swap space in to RAM. If you have a bunch of idle processes that rarely need time, this isn't super terrible.

But Java magnifies the problem. When you run out of physical RAM, some of that RAM is swapped out to disk. When some of that RAM is Java heap, then you have a big problem when the garbage collector kicks in. Because, in general, the GC touches every page of the heap. That means that all of the heaps pages need to be "active", and thus, "swapped in".

But if they don't fit, then you have a problem like the 8 puzzle. Where you're shifting memory in and out from disk. This is called thrashing.

A swapped JVM heap that is GC is the text book case of worst case thrashing.

The machine is letting you allocate the extra memory because it thinks you have more, since your Virtual Memory (physical RAM + swap) is greater

 

How to install google play on AOSP emulator

I want to know how google play install an app and why no dialog popup when google play install an app

currently PackageInstallActivity dialog will pop up even no any permission is required by the app which fdroid is installing

  1. download Gapps from https://opengapps.org/, e.g. I download open_gapps-arm64-9.0-stock-20191213
  2. mkdir -p device/xxx/apps
  3. add file device device/xxx/apps/Android.mk and edit as below
    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)
    LOCAL_MODULE := Phonesky
    LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
    LOCAL_CERTIFICATE := PRESIGNED
    LOCAL_PRIVILEGED_MODULE := true
    LOCAL_MODULE_CLASS := APPS
    LOCAL_MODULE_TAGS := optional
    LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
    LOCAL_DEX_PREOPT := true
    include $(BUILD_PREBUILT)

    include $(CLEAR_VARS)
    LOCAL_MODULE := GoogleServicesFramework
    LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
    LOCAL_CERTIFICATE := PRESIGNED
    LOCAL_PRIVILEGED_MODULE := true
    LOCAL_MODULE_CLASS := APPS
    LOCAL_MODULE_TAGS := optional
    LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
    LOCAL_DEX_PREOPT := true
    include $(BUILD_PREBUILT)

    include $(CLEAR_VARS)
    LOCAL_MODULE := PrebuiltGmsCore
    LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
    LOCAL_CERTIFICATE := PRESIGNED
    LOCAL_PRIVILEGED_MODULE := true
    LOCAL_MODULE_CLASS := APPS
    LOCAL_MODULE_TAGS := optional
    LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
    LOCAL_DEX_PREOPT := true
    include $(BUILD_PREBUILT)

    include $(CLEAR_VARS)
    LOCAL_MODULE := GmsCoreSetupPrebuilt
    LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
    LOCAL_CERTIFICATE := PRESIGNED
    LOCAL_PRIVILEGED_MODULE := true
    LOCAL_MODULE_CLASS := APPS
    LOCAL_MODULE_TAGS := optional
    LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
    LOCAL_DEX_PREOPT := true
    include $(BUILD_PREBUILT)

  4. copy below 4 apps to device/xxx/apps/
    these 4 apps are required for login and install apps from google play
    Phonesky.apk, GoogleServicesFramework.apk, PrebuiltGmsCorePi.apk, GmsCoreSetupPrebuilt.apk
  5. update device/xxx/xxx_common.mk as below
    PRODUCT_PACKAGES += \
    libg1 \
    libhantro \
    – libcodec
    + libcodec \
    + Phonesky \
    + GoogleServicesFramework \
    + PrebuiltGmsCorePi \
    + GmsCoreSetupPrebuilt
  6. make and flash images to your device
  7. boot to Android OS and open google play, then you will see below messages
    0
  8. please read the part for custom rom users
    open https://g.co/AndroidDeviceRegistration
  9. adb shell ‘sqlite3 /data/data/com.google.android.gsf/databases/gservices.db “select * from main where name = \"android_id\";"‘
  10. 0
  11. and register your Google Service Framework Android ID
    you should can login google play after about 20 mins(according to my experience)