Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] builds will likely break on RN 0.75 / Expo 52 #2812

Open
jamsch opened this issue Aug 3, 2024 · 27 comments
Open

[Android] builds will likely break on RN 0.75 / Expo 52 #2812

jamsch opened this issue Aug 3, 2024 · 27 comments

Comments

@jamsch
Copy link

jamsch commented Aug 3, 2024

Hi,

Just letting the maintainers of this library know that the enableJetifier option will be removed from upstream React Native / Expo:

facebook/react-native@14ccf6b
expo/expo@3774717#diff-c1abe9eea32a8e683dbea2f18a322cc0b8c5a4ce1a8da1719c6a9ddf29f79e3fL28

Because the enableJetifier option is removed, the following lines:

https://github.com/dooboolab-community/react-native-iap/blob/561586988df9bf9b282f7fca410d2c4eb25cf587/android/build.gradle#L171-L174

Resolves in a bare Expo SDK 51 app as the following:

+--- project :react-native-iap
|    +--- com.android.support:support-annotations:28.0.0
|    +--- com.android.support:customtabs:28.0.0

Which results in the following error:

> Task :app:processDebugMainManifest FAILED
/home/expo/workingdir/build/android/app/src/debug/AndroidManifest.xml:28:18-86 Error:
   Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.12.0] AndroidManifest.xml:28:18-86
   is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
   Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:6:5-162 to override.

For context, earlier this week I had run in to this issue after Expo deployed an update to their bare native template that included the removal of enableJetifier, but it was later reverted because of the above build issue mentioned here: expo/expo#30725

@leaguefun
Copy link

@jamsch FYI, I tried to remove the line "supportLibVersion" in android/build.gradle, that can fix the build broken

@sburgpit
Copy link

sburgpit commented Sep 3, 2024

@leaguefun I ran into the same problem on RN 0.75.2 and removing the supportLibVersion really fixed the build. However, it seems to be something important, can we just get rid of it?

@DarkShtir
Copy link

Same error
Maybe someone has information about supportLibVersion filed??

@AruSeito
Copy link

diff --git a/android/build.gradle b/android/build.gradle
index e4a79ccdf9ea72bf44f82fccdeb2162a06266109..db64cfcf212c09756fcf26aea8077282592f7f86 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -169,22 +169,17 @@ dependencies {
 
   amazonImplementation  "com.amazon.device:amazon-appstore-sdk:$amazonSdkVersion"
 
-  if (supportLibVersion && androidXVersion == null) {
-    implementation "com.android.support:support-annotations:$supportLibVersion"
-    implementation "com.android.support:customtabs:$supportLibVersion"
-  } else {
-    def defaultAndroidXVersion = "1.2.0"
+  def defaultAndroidXVersion = "1.2.0"
 
-    if (androidXVersion == null) {
-      androidXVersion = defaultAndroidXVersion
-    }
+  if (androidXVersion == null) {
+    androidXVersion = defaultAndroidXVersion
+  }
 
-    def annotationVersion = androidXAnnotation ? androidXAnnotation : androidXVersion
-    def browserVersion = androidXBrowser ? androidXBrowser : androidXVersion
+  def annotationVersion = androidXAnnotation ? androidXAnnotation : androidXVersion
+  def browserVersion = androidXBrowser ? androidXBrowser : androidXVersion
 
-    implementation "androidx.annotation:annotation:$annotationVersion"
-    implementation "androidx.browser:browser:$browserVersion"
-  }
+  implementation "androidx.annotation:annotation:$annotationVersion"
+  implementation "androidx.browser:browser:$browserVersion"
 }
 
 if (isNewArchitectureEnabled()) {
diff --git a/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt b/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt
index c1bc5afdea0d61629c630b73c6cb08f25eaf49a1..ffaa969311e17e725bdc1133665245cdc05da22f 100644
--- a/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt
+++ b/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt
@@ -37,7 +37,7 @@ fun Promise.safeReject(
     throwable: Throwable?,
 ) {
     try {
-        this.reject(code, message, throwable)
+        this.reject(code ?: "", message, throwable)
     } catch (oce: ObjectAlreadyConsumedException) {
         Log.d(TAG, "Already consumed ${oce.message}")
     }

I create this patches, this can fix the build error when use expo 52 & reactNative 0.76

@alterx
Copy link

alterx commented Oct 31, 2024

I'm testing the SDK 52.0.0-preview.12 and RN 0.76.1 and can confirm that the Android build is broken

[RUN_GRADLEW] /private/var/folders/5p/v8tzckhs3958w1zth99dtlbc0000gp/T/eas-build-local-nodejs/95e05321-767b-41ec-8305-0834978db28c/build/packages/munity-app/android/app/src/main/AndroidManifest.xml:28:18-86 Error:
[RUN_GRADLEW] 	Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.13.1] AndroidManifest.xml:28:18-86
[RUN_GRADLEW] 	is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
[RUN_GRADLEW] 	Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:27:3-55:17 to override.

...

[RUN_GRADLEW] FAILURE: Build completed with 2 failures.
[RUN_GRADLEW] 1: Task failed with an exception.
[RUN_GRADLEW] -----------
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] Execution failed for task ':app:processReleaseMainManifest'.
[RUN_GRADLEW] > Manifest merger failed with multiple errors, see logs
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] > Run with --stacktrace
[RUN_GRADLEW] option to get the stack trace.
[RUN_GRADLEW] > Run with --info or --debug option to get more log output.
[RUN_GRADLEW] > Run with --scan to get full insights.
[RUN_GRADLEW] > Get more help at https://help.gradle.org.
[RUN_GRADLEW] ==============================================================================
[RUN_GRADLEW] 2: Task failed with an exception.
[RUN_GRADLEW] -----------
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] Execution failed for task ':app:mergeReleaseResources'.
[RUN_GRADLEW] > A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
[RUN_GRADLEW]    > Resource compilation failed (Failed to compile values resource file /private/var/folders/5p/v8tzckhs3958w1zth99dtlbc0000gp/T/eas-build-local-nodejs/95e05321-767b-41ec-8305-0834978db28c/build/packages/munity-app/android/app/build/intermediates/incremental/release/mergeReleaseResources/merged.dir/values/values.xml. Cause: java.lang.IllegalStateException: Can not add resource (com.android.aaptcompiler.ParsedResource@60d70919) to table.). Check logs for more details.
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] > Run with --stacktrace option to get the stack trace.
[RUN_GRADLEW] > Run with --info or --debug option to get more log output.
[RUN_GRADLEW] > Run with --scan to get full insights.
[RUN_GRADLEW] > Get more help at https://help.gradle.org.
[RUN_GRADLEW] ==============================================================================
[RUN_GRADLEW] BUILD FAILED in 8m 57s

@jamsch
Copy link
Author

jamsch commented Nov 3, 2024

Should be fixed on latest version

@jamsch jamsch closed this as completed Nov 3, 2024
@CoatedMoose
Copy link

@jamsch Where/how is this issue addressed? Currently, the latest is of react-native-iap is 12.15.7 (which I'm using) , but I'm receiving the error mentioned above.

Here's the simplest way I reproduced the issue:

npx [email protected] StickerSmash
cd StickerSmash
npx expo prebuild --platform android
# confirmed everything works by running `npx expo run:android`
npx expo install react-native-iap
npx expo prebuild --platform android
# checked node_modules/react-native-iap/package.json lists [email protected]
npx expo run:android
# fails with error you mentioned in the issue description

@benawad
Copy link

benawad commented Nov 15, 2024

@CoatedMoose I'm in the same boat. I was able to get it to build by changing this file benawad@9c2c2a8 but idk if it will break anything in production. Just doing a dev build right now

@CoatedMoose
Copy link

@benawad I can see how that would work. The project can clearly depend on either androidx or support library - if it's working for you at all, I would not expect any issue. That change you referenced will be at the expense of compatibility (anyone that still depends on the support lib).

The check you're deleting in favour of an explicit dependency is assuming the support lib when supportLibVersion is defined (and androidx version is not set), but the expo config plugin always adds that definition. I expect the necessary patch will be either:

  • to make the addition conditional based on a plugin config arg
  • remove it entirely, and rely on the referenced property:
    def supportLibVersion = getExtOrDefault("supportLibVersion")

@WhidRubeld
Copy link

WhidRubeld commented Nov 20, 2024

I confirm that this issue exists.

The issue arose after updating an Expo-managed project to SDK 52.

react-native 0.76.2
react-native-iap ^12.15.2

@WhidRubeld
Copy link

WhidRubeld commented Nov 20, 2024

react-native 0.76.2 react-native-iap ^12.15.2

Updating to 12.15.7 did not solve this problem.

> Task :app:processDebugMainManifest FAILED
[androidx.versionedparcelable:versionedparcelable:1.1.1] /home/expo/.gradle/caches/8.10.2/transforms/55fcebbdc103881312bd0bf08179bc94/transformed/versionedparcelable-1.1.1/AndroidManifest.xml Warning:
	Namespace 'androidx.versionedparcelable' is used in multiple modules and/or libraries: androidx.versionedparcelable:versionedparcelable:1.1.1, com.android.support:versionedparcelable:28.0.0. Please ensure that all modules and libraries have a unique namespace. For more information, See https://developer.android.com/studio/build/configure-app-module#set-namespace
See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger.
/home/expo/workingdir/build/android/app/src/debug/AndroidManifest.xml:28:18-86 Error:
	Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.13.1] AndroidManifest.xml:28:18-86
	is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
	Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:6:5-162 to override.

Why is the issue closed before it is actually solved?

@tiyo
Copy link

tiyo commented Nov 22, 2024

Has this issue been resolved? I have been unable to find the cause, and I am in urgent need to debug the Android payment function.

@tiyo
Copy link

tiyo commented Nov 23, 2024

solved:

react-native-iap/android/build.gradle
remove def supportLibVersion = getExtOrDefault("supportLibVersion")
#maybe useful

android/gradle.properties
android.enableJetifier=true

prebuild, clean gradlew & cache

-------UPDATE
Correction, it has not been resolved yet, it can only run on the simulator, and using EAS cannot package it. The Expo official team has not yet responded.

@hernanjoseDev
Copy link

I had exactly the same problem.
The problem was with the react-native-iap library.
Since I didn't use it in my project, I uninstalled it.
I had it installed for future integration but for now I will look for another option.

RN: 0.76.3
Expo: 52.0.11

@sadenisa
Copy link

solved:

react-native-iap/android/build.gradle remove def supportLibVersion = getExtOrDefault("supportLibVersion") #maybe useful

android/gradle.properties android.enableJetifier=true

prebuild, clean gradlew & cache

-------UPDATE Correction, it has not been resolved yet, it can only run on the simulator, and using EAS cannot package it. The Expo official team has not yet responded.

Same problem. Any updates?
Thanks

@LeandroTamola
Copy link

LeandroTamola commented Nov 28, 2024

Still happening with:

"expo": "^52.0.11",
"react-native": "0.76.3",
"react-native-iap": "^12.15.7",

@jamsch jamsch reopened this Nov 28, 2024
@agendartdelucca
Copy link

I am facing the same problem, and now I am really stucked to update my app 😞 ... I just tried to downgrade to Expo version to SDK 51 and other problems appears, both on iOS and android.

Is there any update on this?

@WhidRubeld
Copy link

WhidRubeld commented Nov 29, 2024

Workaround for building Expo apps with EAS

Add postinstall.js file to root dir

const fs = require('fs')
const path = require('path')

const gradleFilePath = path.join(
  __dirname,
  '..',
  'node_modules',
  'react-native-iap',
  'android',
  'build.gradle',
)

try {
  let gradleFileContent = fs.readFileSync(gradleFilePath, 'utf8')
  const lineToReplace =
    'def supportLibVersion = getExtOrDefault("supportLibVersion")'

  if (gradleFileContent.includes(lineToReplace)) {
    gradleFileContent = gradleFileContent.replace(
      lineToReplace,
      'def supportLibVersion = false',
    )

    fs.writeFileSync(gradleFilePath, gradleFileContent, 'utf8')
    console.log('Line removed from build.gradle successfully.')
  } else {
    console.log('Line not found in build.gradle.')
  }
} catch (error) {
  console.error('Failed to modify build.gradle:', error)
}

Add post-script to package.json

{
  ...
  "scripts": {
    ...
    "postinstall": "node postinstall.js"
  },
  ...
}

Run eas build ... command

@otmancra
Copy link

Thank you @WhidRubeld for providing the postinstall.js workaround! I tried your solution, but I encountered the following error when running it during the build:

$ node postinstall.js Failed to modify build.gradle: Error: ENOENT: no such file or directory, open '/home/expo/workingdir/node_modules/react-native-iap/android/build.gradle'

It seems the issue was related to the script using __dirname to construct the path, but during the build, the working directory was actually /home/expo/workingdir/build. This caused the script to fail because it was looking in the wrong location for the build.gradle file.

To fix this, I updated the script to use process.cwd() instead of __dirname to dynamically determine the current working directory. Here’s the updated script:

const fs = require('fs');
const path = require('path');

// Use process.cwd() to dynamically get the working directory
const workingDir = process.cwd();

const gradleFilePath = path.join(
    workingDir,
    'node_modules',
    'react-native-iap',
    'android',
    'build.gradle'
);

if (!fs.existsSync(gradleFilePath)) {
    console.error('Gradle file does not exist at:', gradleFilePath);
    process.exit(0); // Exit gracefully if the file doesn't exist
}

try {
    let gradleFileContent = fs.readFileSync(gradleFilePath, 'utf8');
    const lineToReplace =
        'def supportLibVersion = getExtOrDefault("supportLibVersion")';

    if (gradleFileContent.includes(lineToReplace)) {
        gradleFileContent = gradleFileContent.replace(
            lineToReplace,
            'def supportLibVersion = false'
        );

        fs.writeFileSync(gradleFilePath, gradleFileContent, 'utf8');
        console.log('Line removed from build.gradle successfully.');
    } else {
        console.log('Line not found in build.gradle.');
    }
} catch (error) {
    console.error('Failed to modify build.gradle:', error);
}

After making this change, the script worked as expected during the build process. Thank you again for the starting point, it really helped! I hope this updated version can assist others who might encounter a similar issue with the working directory.

@zallesov
Copy link

zallesov commented Dec 2, 2024

I could solve this problem with jetifier

install jetifier

yarn add jetifier

and enable it in gradle.properties

android.enableJetifier=true

then run

npx jetify     

What it does is it replaces all com.android.support dependencies to android. Don't ask me why

after that I could run

./gradlew app:assembleDebug --debug

and starn the app in emulator

@mihalcinD
Copy link

I confirm the issue is still happening. Setting def supportLibVersion = false in the react-native-iap/android/build.gradle helped.

@leacode
Copy link

leacode commented Dec 5, 2024

Two ways to make android app able to run:

  • define android.enableJetifier=true in gradle.properties
  • comment out supportLibVersion = xxx in build.gradle

Unfortunately, my project is using expo 52 and create android project from nothing every time when build. There's no way to config these two files.

I hope this issue can be fixed soon without updating android project manually each time.

@AdamGerthel
Copy link

I have the same issue, see expo/expo#30725

This seems to be pretty urgent as it's incompatible with the latest Expo updates.

@Guybaron14
Copy link

still having it :((

"expo": "^52.0.19", "react-native": "0.76.5", "react-native-iap": "^12.15.7",

@frussodesigns
Copy link

Thank you @WhidRubeld for providing the postinstall.js workaround! I tried your solution, but I encountered the following error when running it during the build:

$ node postinstall.js Failed to modify build.gradle: Error: ENOENT: no such file or directory, open '/home/expo/workingdir/node_modules/react-native-iap/android/build.gradle'

It seems the issue was related to the script using __dirname to construct the path, but during the build, the working directory was actually /home/expo/workingdir/build. This caused the script to fail because it was looking in the wrong location for the build.gradle file.

To fix this, I updated the script to use process.cwd() instead of __dirname to dynamically determine the current working directory. Here’s the updated script:

const fs = require('fs');
const path = require('path');

// Use process.cwd() to dynamically get the working directory
const workingDir = process.cwd();

const gradleFilePath = path.join(
    workingDir,
    'node_modules',
    'react-native-iap',
    'android',
    'build.gradle'
);

if (!fs.existsSync(gradleFilePath)) {
    console.error('Gradle file does not exist at:', gradleFilePath);
    process.exit(0); // Exit gracefully if the file doesn't exist
}

try {
    let gradleFileContent = fs.readFileSync(gradleFilePath, 'utf8');
    const lineToReplace =
        'def supportLibVersion = getExtOrDefault("supportLibVersion")';

    if (gradleFileContent.includes(lineToReplace)) {
        gradleFileContent = gradleFileContent.replace(
            lineToReplace,
            'def supportLibVersion = false'
        );

        fs.writeFileSync(gradleFilePath, gradleFileContent, 'utf8');
        console.log('Line removed from build.gradle successfully.');
    } else {
        console.log('Line not found in build.gradle.');
    }
} catch (error) {
    console.error('Failed to modify build.gradle:', error);
}

After making this change, the script worked as expected during the build process. Thank you again for the starting point, it really helped! I hope this updated version can assist others who might encounter a similar issue with the working directory.

Anybody got this workaround to work with going through EAS? I tried both WhidRubeld and otmancra workarounds to no avail. Removing the line "supportLibVersion" in android/build.gradle works but only locally.

@WhidRubeld
Copy link

Anybody got this workaround to work with going through EAS? I tried both WhidRubeld and otmancra workarounds to no avail. Removing the line "supportLibVersion" in android/build.gradle works but only locally.

Maybe you are doing a production build. In this case you will have to connect the script like this in package.json.

{
  "scripts": {
     "eas-build-post-install": "node postinstall.js"
  }
}

https://docs.expo.dev/build-reference/npm-hooks/

@Ash-hs
Copy link

Ash-hs commented Dec 25, 2024

this pr #2904 can fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests