braze-inc / braze-react-native-sdk

Public repo for the Braze React Native SDK
https://www.braze.com
Other
64 stars 84 forks source link

[Bug]: Build Fails in RN 0.72.0 #222

Closed YasirFiz closed 1 year ago

YasirFiz commented 1 year ago

Which Platforms?

Android

Which React Native Version?

72.0

Which @braze/react-native-sdk SDK version?

5.1.0

Repro Rate

100%

Steps To Reproduce

Build android

Expected Behavior

build successfully

Actual Incorrect Behavior

Screenshot 2023-06-23 at 4 34 44 PM

Verbose Logs

No response

Additional Information

No response

bryanlogan commented 1 year ago

Can you post your gradle version and your android/app/build.gradle file?

YasirFiz commented 1 year ago

Gradle Version: 8.0.1

apply plugin: "com.facebook.react"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

project.ext.envConfigFiles = [
    productionDebug: ".env.production",
    productionRelease: ".env.production",
    stagingRelease: ".env.staging",
    stagingDebug: ".env.staging",
    devRelease: ".env.dev",
    devDebug: ".env.dev"
]

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */

react {
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '..'
    // root = file("../")
    //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
    // reactNativeDir = file("../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
    // codegenDir = file("../node_modules/@react-native/codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
    // cliFile = file("../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]
}

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US. Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    namespace "com.fiz"
    defaultConfig {
        applicationId "com.fiz"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
        versionCode 10035
        versionName "6.1.0"
        resValue "string", "build_config_package", "com.fiz"
        resValue "string", "CodePushDeploymentKey", '""'
        resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
    }
    signingConfigs {
        debug {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            firebaseCrashlytics {
                nativeSymbolUploadEnabled true
                unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
            }
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    flavorDimensions "default"
    productFlavors {
        dev {
            applicationIdSuffix ".dev"
        }
        staging {
            applicationIdSuffix ".staging"
        }
        production {
        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }

    implementation files('libs/adjust-lib.aar')
    implementation "androidx.core:core-splashscreen:1.0.0-beta01"
    implementation(project(':react-native-maps')){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:17.6.0'
    implementation 'com.google.android.gms:play-services-maps:18.0.0'
    implementation 'com.android.installreferrer:installreferrer:1.0'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
phatlaunchdeck commented 1 year ago

While waiting for the maintainers to update the library, you can update build.gradle file of Braze to these options as Java 11 is the default since RN 70 I believe:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
  }

  kotlinOptions {
    freeCompilerArgs = ['-Xjvm-default=all']
    jvmTarget = "11"
  }
radixdev commented 1 year ago

Hi @YasirFiz ,

Please provide/upload a concise self-contained sample application that reproduces the issue. We're having trouble reproducing what you're seeing and require more concrete steps on recreating the issue.

phatlaunchdeck commented 1 year ago

@radixdev I think it's pretty easy to reproduce, just init a new (bare) React Native project with version 0.72, install Braze SDK and then hit build on Android, you'll see it right away. This is provided that your Android Studio is using the latest bundled Gradle JDK of version 17.0.6.

YasirFiz commented 1 year ago

@radixdev It is as simple as @phatlaunchdeck said also The solution

While waiting for the maintainers to update the library, you can update build.gradle file of Braze to these options as Java 11 is the default since RN 70 I believe:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
  }

  kotlinOptions {
    freeCompilerArgs = ['-Xjvm-default=all']
    jvmTarget = "11"
  }

works, so is a simple fix. But would be good to have this fixed in library so that user do not have to patch-package

radixdev commented 1 year ago

Hi @phatlaunchdeck ,

Thanks for the reproduction step. Although the log for me was not an error but a warning, we'll still update the buildscript to reflect the java version and correct it. We'll update this thread once this is released.

radixdev commented 1 year ago

This is now merged in our private repo. We will update this issue once it's live.

hokstuff commented 1 year ago

Hi @YasirFiz and @phatlaunchdeck,

We just released React Native SDK 5.2.0 which contains a fix for this issue.

Thanks!