Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RenderScript and PlayStore 64-bit requirement

UPDATE: OK, so I've looked into this a bit further. Managed to use bundletool to try and test the different apks, and found this:

"App Bundle contains 32-bit RenderScript bitcode file (.bc) which disables 64-bit support in Android."

Does anyone know how I can fix this? The renderscript forms a pretty important part of the project.

I'm trying to get my app 64-bit compatible for the new PlayStore requirement. We do use RenderScript in the app, so I was wondering if this will cause issues? And, how does one fix those issues? The renderscript is a very tiny script that just outputs a bitmap with green or red sections depending on the input.

#pragma version(1)
#pragma rs java_package_name(za.co.overtake)

int*reds;
int*greens;
int*blues;
int imgWidth;

uchar4 RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) {
   bool colourme = false;

   for(int col = 0; col < imgWidth; col++){

      const int red = reds[col];
      const int green = greens[col];
      const int blue = blues[col];

      if (in.r == red && in.g == green && in.b == blue){
        colourme = true;
       }
   }
   if (colourme) {
      // Cannot increase red amount much as it will cause issues when capturing the image in 565
      // format.
      in.r = 100;
      in.g = 10;
      in.b = 10;
      in.a = 100;
   } else if (in.a > 200) {
       in.r = 21;
       in.g = 63;
       in.b = 81;
       in.a = 100;
   } else {
      in.r = 0;
      in.g = 0;
      in.b = 0;
      in.a = 0;
   }
return in;
}

we call this script in java like so:

  final RenderScript rs = RenderScript.create(this);

    final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);
    final Allocation output = Allocation.createTyped(rs, input.getType());
    final ScriptC_singlesource script = new ScriptC_singlesource(rs);

    Allocation red = Allocation.createSized(rs, Element.I32(rs), reds.length);
    red.copyFrom(reds);
    script.bind_reds(red);

    Allocation green = Allocation.createSized(rs, Element.I32(rs), greens.length);
    green.copyFrom(greens);
    script.bind_greens(green);

    Allocation blue = Allocation.createSized(rs, Element.I32(rs), blues.length);
    blue.copyFrom(blues);
    script.bind_blues(blue);

    script.set_imgWidth(noOfColours);
    script.forEach_root(input, output);
    output.copyTo(bitmap);

    RenderScript blur = RenderScript.create(this);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(blur, Element.U8_4(blur));
    Allocation tmpIn = Allocation.createFromBitmap(blur, bitmap);
    Allocation tmpOut = Allocation.createFromBitmap(blur, bitmap);
    theIntrinsic.setRadius(4.0f);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(bitmap);

The Android Developer documentation states that using any C or C++ code could make your app incompatible. But, I couldn't find a solution to RenderScript specifically.

like image 470
Zee Avatar asked May 29 '19 08:05

Zee


1 Answers

OK, so it turns out I had to do two things:

  1. Use a more recent version of Renderscript. I went with targeting 22, and setting renderscriptSupportModeEnabled to true. ALSO, had to make sure that I was using android.support.v8.renderscript.RenderScript and not android.Renderscript.

  2. Revert AndroidX. This was a mission! Had to take androidX out since, for some reason, it just refused to play nicely with Renderscript. For example, it would crash on Android5 and just refused to be 64 bit compatible.

I hope this helps someone out there!

O, and as a last tidbit: You can test whether your bundle is 64 bit compatible by using bundletool. I found this site to be extremely useful: https://www.raywenderlich.com/9043-android-app-bundles-getting-started

-- it will tell you if it cannot build the 64 bit apks.

UPDATE: Another discovery! So, following all these steps, you will notice that all the 64 bit folders are generated in your APK. However, if you are using an external library that does not have all the 64 bit requirements: GOOGLE WILL NOT PICK THIS UP! It seems to only do a check on whether the folders are present and does not check that all the content required in each folder is present. This caused my project with renderscript to be 'compatible' even though it used a library where the x86_64 was MISSING! (Long story short: my other projects did not want to work as 64-bit compatible and I finally tracked it down to the library and NOT using renderscript. My solution was to remove support for x86 as we do not have those device in my country anyway.)

UPDATE: Using the latest BuildToolsVersion (29.0.3), along with androidX, seems to be working fine :D!

Also have

 renderscriptTargetApi 22
 renderscriptSupportModeEnabled true
like image 76
Zee Avatar answered Sep 27 '22 18:09

Zee