RonRadtke / react-native-blob-util

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
746 stars 128 forks source link

Android missing compileOptions in build.gradle #200

Open axolotl0212 opened 1 year ago

axolotl0212 commented 1 year ago

Cannot build Android app after upgrading to 0.17.0.

Lambda expression (Java 8) is used in Android source file

https://github.com/RonRadtke/react-native-blob-util/blob/977a5a908116ae8afa8b7d59efae4ffde81aaa56/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilPackage.java#L28

However compileOptions is not explicitly specified in build.gradle, leading to compilation error

Related issue in other repo: https://github.com/OneSignal/react-native-onesignal/issues/1235

Suggest adding the compileOptions to build.gradle to enable desugaring, as follow:

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ...
}
chenyulun commented 1 year ago

/android/build.gradle

import com.android.build.gradle.BaseExtension

allprojects {
// ...
getSubprojects().each {
        Project currentProject = it
        currentProject.afterEvaluate {
            try {
                BaseExtension android = currentProject.extensions.getByName('android')
                android.compileOptions {
                    sourceCompatibility JavaVersion.VERSION_1_8
                    targetCompatibility JavaVersion.VERSION_1_8
                }
            } catch(e) {
            }
        }
    }
}