Skip to content

Commit 3846426

Browse files
authored
fix: don't use deprecated package field in AndroidManifest on AGP >= 7.3 (#420)
### Summary Follow-up to #399 Currently there's a deprecation warning for the `package` field in `AndroidManifest.xml` when using Android Gradle Plugin >= 7.3. This adds a separate `AndroidManifest` file that'll be used for older versions of Android Gradle Plugin to avoid the deprecation warning on newer versions. ### Test plan - Verify CI passes - Verify building and running various templates
1 parent 9189852 commit 3846426

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

packages/create-react-native-library/templates/native-common/android/build.gradle

+18-4
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,28 @@ def getExtOrIntegerDefault(name) {
6464
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["<%- project.name -%>_" + name]).toInteger()
6565
}
6666

67-
def isAGPVersionGreaterThan(version) {
68-
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
69-
return agpVersion > version
67+
def supportsNamespace() {
68+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
69+
def major = parsed[0].toInteger()
70+
def minor = parsed[1].toInteger()
71+
72+
// Namespace support was added in 7.3.0
73+
if (major == 7 && minor >= 3) {
74+
return true
75+
}
76+
77+
return major >= 8
7078
}
7179

7280
android {
73-
if (isAGPVersionGreaterThan(7)) {
81+
if (supportsNamespace()) {
7482
namespace "com.<%- project.package -%>"
83+
} else {
84+
sourceSets {
85+
main {
86+
manifest.srcFile "src/main/AndroidManifestDeprecated.xml"
87+
}
88+
}
7589
}
7690

7791
<% if (project.cpp || (project.view && (project.arch === "new" || project.arch === "mixed"))) { -%>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.<%- project.package -%>">
3-
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
42
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.<%- project.package -%>">
3+
</manifest>

0 commit comments

Comments
 (0)