Expo detached android application crashing on andoroid 5.1

When i detach the android application by using ‘exp detach’ command. Android code is downloaded as i use a windows machine.
→ On opening the android code in android studio, i get an exception after syncing “No resource found that matches the given name: attr 'android:keyboardNavigationCluster+” .

I have to update the build tools and supported library version to 27.0.3 and 27.1.1 in order to make the detached application work. When i do that the detached application works file on android 6.0 and above but it crashes on android 5.1 when i open the detached application.
Can anyone help in making the detached application run fine on android 5.1 or have anyone else encountered this issue.

Hi @ankit992 - sorry, this sounds really frustrating. Can I ask which SDK version is the app you’re trying to detach?

Hi esamelson, Sorry for the late reply. I am using exp version 53.0.0. I am just using exp detach, in terms of android sdk i am interested in android sdk 21 and above.

Hi @ankit992 - sorry, I meant which Expo SDK version is the app you’re trying to target? (Not which Android SDK versions you’d like the app to run on.) The first thing I would suggest is to try upgrading to the newest Expo SDK version, which is 27.

Hi esamelson,
Thanks for the response.
I upgraded our application by following instruction from article Expo SDK v27.0.0 is now available | by Ben Roth | Exposition but we still have the same issue with android 5.1, i detached android application again and after building an apk i am still getting
java.lang.RuntimeException: Unable to instantiate application host.exp.exponent.MainApplication: java.lang.ClassNotFoundException: Didn't find class "host.exp.exponent.MainApplication" on path: DexPathList

Before this error i got an error about bolts-applinks library so i added compile ‘com.parse.bolts:bolts-tasks:1.4.0’
compile ‘com.parse.bolts:bolts-applinks:1.4.0’ to fix those errors in the build.gradle of project.
But i am still unable to run the application on android 5.1
Is there anything i can try to fix this?

Hi @ankit992 - ah, this is a known issue with the devDebug target on android 5.1 and below. You can try using the dev19Debug target instead (./gradlew installDev19Debug), which has slightly different behavior regarding multidex. If that doesn’t work, however, you may need to just build and sign a release apk for testing on that particular device, as the release target does not have any of these issues. Sorry for the inconvenience!

Hi @esamelson, i tried using dev19Debug, i am getting
Too many classes in --main-dex-list, main dex capacity exceeded
I am unable to install dev19Debug variant in emulator.

Also i tried using the release version of dev19Debug i got the error
ENOENT: no such file or directory, open 'C:\expo-boilerplate\swipe\android\app\src\main\assets\shell-app-manifest.json'

Hi @ankit992 - try running exp publish before doing your release version build. (And prodRelease should do the trick – no need to use dev19).

Really sorry for the trouble!

Hi Thanks Emanuel, i was able to run it with a prodRelease build on android 5.1.1 and it was running fine, but the app crashes within 5 seconds of opening and when i try to change the javascript code in the app, it doesn’t get loaded in the detached apk. I just see a dotted rounded off square on a white screen, and after about 5 seconds it crashes.
Should i start a new thread for this or should we continue in this thread for this issue ?

Hi @ankit992 - it sounds like there is likely an error in your JS that is causing the app to crash as soon as it loads. If you run adb logcat, are there any interesting logs from your device when the crash happens?

Hi yes found something interesting in adb logs:

05-15 22:10:17.457 11778-11778/com.testProject E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.testProject, PID: 11778
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testProject/host.exp.exponent.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2720)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:241)
        at android.app.ActivityThread.main(ActivityThread.java:6274)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
        at host.exp.exponent.ExponentManifest.fetchCachedManifest(ExponentManifest.java:276)
        at host.exp.exponent.AppLoader.start(AppLoader.java:85)
        at host.exp.exponent.experience.DetachActivity.onCreate(DetachActivity.java:88)
        at android.app.Activity.performCreate(Activity.java:6720)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2673)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:241) 
        at android.app.ActivityThread.main(ActivityThread.java:6274) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
05-15 22:10:27.302 11778-11858/com.testProject E/com.amplitude.api.DeviceInfo: Encountered an error connecting to Google Play Services
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
        at com.amplitude.api.DeviceInfo$CachedInfo.getAndCacheGoogleAdvertisingId(DeviceInfo.java:207)
        at com.amplitude.api.DeviceInfo$CachedInfo.getAdvertisingId(DeviceInfo.java:187)
        at com.amplitude.api.DeviceInfo$CachedInfo.<init>(DeviceInfo.java:57)
        at com.amplitude.api.DeviceInfo$CachedInfo.<init>(DeviceInfo.java:42)
        at com.amplitude.api.DeviceInfo.getCachedInfo(DeviceInfo.java:260)
        at com.amplitude.api.DeviceInfo.prefetch(DeviceInfo.java:266)
        at com.amplitude.api.AmplitudeClient$2.run(AmplitudeClient.java:285)
        at com.amplitude.api.AmplitudeClient.runOnLogThread(AmplitudeClient.java:1793)
        at com.amplitude.api.AmplitudeClient.initializeDeviceInfo(AmplitudeClient.java:280)
        at com.amplitude.api.AmplitudeClient.access$100(AmplitudeClient.java:40)
        at com.amplitude.api.AmplitudeClient$1.run(AmplitudeClient.java:232)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:241)
        at android.os.HandlerThread.run(HandlerThread.java:61)

This is a new project created with exp 53.1.0 and the only command i ran was npm install and then exp detach. This is on windows with an Sony Xperia z5, Doing the same on mac os with same exp version, i was able to run the application and it didn’t crash, but on making changes in javascript code, it didn’t reflect on the emulator/phone(moto e4) i was using.

Hi @ankit992 - have you tried running exp publish before you do a release build?

HI @esamelson I’ve tried building release apk after exp publish, the above explanation was for debug version. Both of them have this issue of the actual js code not loading but the base starter code with a dotted rectangle screen is shown instead.

@ankit992 - could you post the contents of your app.json?

Hi @esamelson,

{
  "expo": {
    "name": "testproject",
    "description": "This project is really great.",
    "slug": "testproject",
    "privacy": "public",
    "sdkVersion": "27.0.0",
    "platforms": [
      "ios",
      "android"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    },
    "isDetached": true,
    "detach": {
      "androidExpoViewUrl": "https://s3.amazonaws.com/exp-exponent-view-code/android-v2.5.1-sdk27.0.0-bb187a9e-e43b-409f-8a5e-c16afa958cca.tar.gz"
    },
    "scheme": "exp413674188b3e4f39963b679471007d90",
    "android": {
      "package": "com.testProject",
      "publishBundlePath": "android\\app\\src\\main\\assets\\shell-app.bundle",
      "publishManifestPath": "android\\app\\src\\main\\assets\\shell-app-manifest.json"
    }
  }
}

Do let me know if you need anything else, and thanks for the help you’re providing with this. :slight_smile:

@ankit992 - I’m a bit confused as it seems like there are multiple things going on here. if you’re running the app in debug mode, you need to have the project running in XDE or via exp start at the time you make the debug build.

If you’re running the app in release mode, you won’t get any updates when you change JS code on your machine, and the app should use the JS code from when you last ran exp publish.

If you’ve tried all of these things, could you clarify what is happening when you run the app in debug mode, and what is happening when you run the app in release mode?

The gray dotted rectangle is just the splash screen that’s shown while the app tries to load your JS.

@esamelson - I created a new Project with exp version 54.0.0 as it was available recently but still facing the same issue. I did the same things, create project with latest xde, then exp detach, then exp publish, then installed the app in my device. It’s still crashing with the same exception in logcat as posted above.

Though the good news is that the release version is working and i can see the reflected js code in the released app after publishing the application again with exp publish.

On Debug side of phone, i’ve tried build variants dev19Debug and devDebug, and on release i’ve tried prodRelease which worked perfectly.

In addition to the above 2 exceptions i just saw an additional one in logcat which can make things easier to debug
05-20 21:58:52.511 24584-24690/com.testProject.testProject E/com.amplitude.api.DeviceInfo: Encountered an error connecting to Google Play Services java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference at com.amplitude.api.DeviceInfo$CachedInfo.getAndCacheGoogleAdvertisingId(DeviceInfo.java:207) at com.amplitude.api.DeviceInfo$CachedInfo.getAdvertisingId(DeviceInfo.java:187) at com.amplitude.api.DeviceInfo$CachedInfo.<init>(DeviceInfo.java:57) at com.amplitude.api.DeviceInfo$CachedInfo.<init>(DeviceInfo.java:42) at com.amplitude.api.DeviceInfo.getCachedInfo(DeviceInfo.java:260) at com.amplitude.api.DeviceInfo.prefetch(DeviceInfo.java:266) at com.amplitude.api.AmplitudeClient$2.run(AmplitudeClient.java:285) at com.amplitude.api.AmplitudeClient.runOnLogThread(AmplitudeClient.java:1793) at com.amplitude.api.AmplitudeClient.initializeDeviceInfo(AmplitudeClient.java:280) at com.amplitude.api.AmplitudeClient.access$100(AmplitudeClient.java:40) at com.amplitude.api.AmplitudeClient$1.run(AmplitudeClient.java:232) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:241) at android.os.HandlerThread.run(HandlerThread.java:61)

Hi @esamelson , on more testing i’ve found that this only appears on windows, if i create and detach a project in mac or linux. The bug doesn’t appear and everything works fine.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.