@@ -36,6 +36,8 @@ class AndroidPlatformContext : public PlatformContext {
3636
3737 jmethodID resolveMethod = env->GetMethodID (blobModuleClass, " resolve" ,
3838 " (Ljava/lang/String;II)[B" );
39+ env->DeleteLocalRef (blobModuleClass);
40+
3941 if (!resolveMethod) {
4042 throw std::runtime_error (" Couldn't find resolve method in BlobModule" );
4143 }
@@ -113,7 +115,7 @@ class AndroidPlatformContext : public PlatformContext {
113115 }).detach ();
114116 }
115117
116- ImageData createImageBitmapFromData (std::span<uint8_t > data) override {
118+ ImageData createImageBitmapFromData (std::span<const uint8_t > data) override {
117119 jni::Environment::ensureCurrentThreadIsAttached ();
118120
119121 JNIEnv *env = facebook::jni::Environment::current ();
@@ -132,12 +134,22 @@ class AndroidPlatformContext : public PlatformContext {
132134 // Decode via BitmapFactory
133135 jclass bitmapFactoryClass =
134136 env->FindClass (" android/graphics/BitmapFactory" );
137+ if (!bitmapFactoryClass) {
138+ env->DeleteLocalRef (byteArray);
139+ throw std::runtime_error (" Couldn't find BitmapFactory class" );
140+ }
135141 jmethodID decodeByteArrayMethod =
136142 env->GetStaticMethodID (bitmapFactoryClass, " decodeByteArray" ,
137143 " ([BII)Landroid/graphics/Bitmap;" );
144+ if (!decodeByteArrayMethod) {
145+ env->DeleteLocalRef (byteArray);
146+ env->DeleteLocalRef (bitmapFactoryClass);
147+ throw std::runtime_error (" Couldn't find decodeByteArray method" );
148+ }
138149 jint length = static_cast <jint>(data.size ());
139150 jobject bitmap = env->CallStaticObjectMethod (
140151 bitmapFactoryClass, decodeByteArrayMethod, byteArray, 0 , length);
152+ env->DeleteLocalRef (bitmapFactoryClass);
141153
142154 if (!bitmap) {
143155 env->DeleteLocalRef (byteArray);
@@ -175,7 +187,7 @@ class AndroidPlatformContext : public PlatformContext {
175187 }
176188
177189 void createImageBitmapFromDataAsync (
178- std::span<uint8_t > data, std::function<void (ImageData)> onSuccess,
190+ std::span<const uint8_t > data, std::function<void (ImageData)> onSuccess,
179191 std::function<void(std::string)> onError) override {
180192 std::thread ([this , ownedData = std::vector<uint8_t >(data.begin (), data.end ()),
181193 onSuccess = std::move (onSuccess),
0 commit comments