1

I want to make some Android applications running in the same process, so I give those apps's AndroidManifest the same sharedUserId:

< manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  ...  
  android:sharedUserId="aaa.bbb" >

and assign each apps's application the same process:

< application
    ...
    android:process="com.mytest" >

It works in android 4.4.4 , all the Applications run in the same Process.

But crash happened in android 6.0.1. When I run the second app, it crashes due to:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}:
  java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication.MainActivity" on path:
  DexPathList[[zip file "/data/app/com.example.myapplication-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-1/lib/arm, /vendor/lib, /system/lib]]

after the system kill the Process, the second app can run and crashes if I run the first application.

It seem that applications can not run in the same process in the same time and I do not know why.

Ken Williams
  • 22,756
  • 10
  • 85
  • 147
Huang Wei
  • 39
  • 3

2 Answers2

0

Each APK has its own ClassLoader. An article talking about this.

So it's normal you can't access a class of another APK. It seems that a security bug was fix between Kitkat and Marshmallow.

Why you need this system ? If it's to share data between application, you could use ContentProvider If it's to launch Activity or Service, you could use Intent with action.

LaurentY
  • 7,495
  • 3
  • 37
  • 55
  • 1
    Thank you ! I read the article. Each Application has a WebView, I want to share the cookies by CookieManager because it is singleton. Maybe there is another way to solve it, but I just want to know how can I shared process in Marshmallow. – Huang Wei Jul 13 '16 at 16:15
0

I fixed it ! disable the options in Android studio ant it works ! enter image description here

Huang Wei
  • 39
  • 3