Skip to content

Commit 5d84038

Browse files
a7medevHeshamMegid
authored andcommitted
fix: fix and enhance AGP namespace support (#1044)
* fix: check for manifest updates before updating The current implementation calculates `isManifestContentUpdated` before applying any modifications to the file, so the manifest file was never updated. The fix was to calculate it right before updating the file. * refactor: enhance AGP namespace support * fix: resolve groovy compile issues * chore(android): keep package in initial manifest * chore: update changelog
1 parent b970960 commit 5d84038

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v12.1.0...dev)
4+
5+
### Fixed
6+
7+
- Fix an issue with Android Gradle Plugin namespace support required for React Native 0.73 and backward compatibility with previous versions ([#1044](https://github.com/Instabug/Instabug-React-Native/pull/1044)).
8+
39
## [12.1.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.1.0...v11.14.0)
410

511
### Added

android/build.gradle

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ apply from: './jacoco.gradle'
44
apply from: './native.gradle'
55
apply from: './sourcemaps.gradle'
66

7-
/* (Preparing to support RN 0.73) Checking APG version to be backward-compatible with RN versions < 0.71 */
8-
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
9-
def shouldUseNameSpace = agpVersion >= 7
10-
def PACKAGE_PROP = "package=\"com.instabug.reactlibrary\""
11-
def manifestOutFile = file("${projectDir}/src/main/AndroidManifest.xml")
12-
def manifestContent = manifestOutFile.getText()
13-
def isManifestContentUpdated = manifestOutFile.getText() != manifestContent
14-
def isPackageNamespaceMissing = !manifestContent.contains("$PACKAGE_PROP")
15-
167
String getExtOrDefault(String name) {
178
def defaultPropertyKey = 'InstabugReactNative_' + name
189
if (rootProject.ext.has(name)) {
@@ -21,28 +12,44 @@ String getExtOrDefault(String name) {
2112
return project.properties[defaultPropertyKey]
2213
}
2314

24-
if(shouldUseNameSpace){
25-
manifestContent = manifestContent.replaceAll(
26-
PACKAGE_PROP,
27-
''
28-
)
29-
} else if(isPackageNamespaceMissing) {
30-
manifestContent = manifestContent.replace(
31-
'<manifest',
32-
"<manifest $PACKAGE_PROP "
33-
)
15+
static boolean supportsNamespace() {
16+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
17+
def major = parsed[0].toInteger()
18+
def minor = parsed[1].toInteger()
19+
20+
// Namespace support was added in 7.3.0
21+
return (major == 7 && minor >= 3) || major >= 8
3422
}
3523

36-
manifestContent.replaceAll(" ", " ")
24+
void updateManifestPackage() {
25+
def packageProp = 'package="com.instabug.reactlibrary"'
26+
def manifestFile = file("$projectDir/src/main/AndroidManifest.xml")
27+
def currentContent = manifestFile.getText()
28+
def content = currentContent
29+
def hasPackage = currentContent.contains(packageProp)
30+
31+
if (supportsNamespace()) {
32+
content = content.replaceAll(packageProp, '')
33+
} else if (!hasPackage) {
34+
content = content.replace(
35+
'<manifest',
36+
"<manifest $packageProp "
37+
)
38+
}
3739

38-
if(isManifestContentUpdated){
39-
manifestOutFile.write(manifestContent)
40+
def shouldUpdateManifest = content != currentContent
41+
if (shouldUpdateManifest) {
42+
manifestFile.write(content)
43+
}
4044
}
4145

46+
updateManifestPackage()
47+
4248
android {
43-
if (shouldUseNameSpace){
44-
namespace = "com.instabug.reactlibrary"
49+
if (supportsNamespace()) {
50+
namespace "com.instabug.reactlibrary"
4551
}
52+
4653
compileSdkVersion getExtOrDefault('compileSdkVersion').toInteger()
4754
buildToolsVersion getExtOrDefault('buildToolsVersion')
4855

android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
1+
<manifest package="com.instabug.reactlibrary"
2+
xmlns:android="http://schemas.android.com/apk/res/android">
33

44
</manifest>
5-

0 commit comments

Comments
 (0)