Skip to content

Commit 00ffd81

Browse files
committed
chore: logging
1 parent fe14a8d commit 00ffd81

File tree

1 file changed

+27
-55
lines changed

1 file changed

+27
-55
lines changed

packages/crashlytics/android/build.gradle

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -125,70 +125,42 @@ ReactNative.module.applyAndroidVersions()
125125
ReactNative.module.applyReactNativeDependency("api")
126126

127127
// Configure automatic NDK symbol upload for release variants if NDK is enabled
128-
if (rootProject.ext && rootProject.ext.firebaseJson) {
129-
def rnfbConfig = rootProject.ext.firebaseJson
130-
131-
if (rnfbConfig.isFlagEnabled('crashlytics_ndk_enabled', false) == true) {
132-
rootProject.afterEvaluate {
128+
// This runs after all projects are evaluated to allow proper configuration
129+
gradle.projectsEvaluated {
130+
if (rootProject.ext && rootProject.ext.firebaseJson) {
131+
def rnfbConfig = rootProject.ext.firebaseJson
132+
133+
if (rnfbConfig.isFlagEnabled('crashlytics_ndk_enabled', false) == true) {
133134
// Find the app project (the one with com.android.application plugin)
134-
def appProject = rootProject.subprojects.find {
135+
def targetAppProject = rootProject.subprojects.find {
135136
it.plugins.hasPlugin('com.android.application')
136137
}
137138

138-
if (appProject != null) {
139-
appProject.afterEvaluate {
140-
try {
141-
def android = appProject.extensions.findByName('android')
142-
143-
if (android != null) {
144-
// Try to configure all release-type variants
145-
try {
146-
android.applicationVariants.all { variant ->
147-
// Match variants with 'release' in the name (case insensitive)
148-
if (variant.name.toLowerCase().contains('release')) {
149-
try {
150-
// Access or create the firebaseCrashlytics extension for this variant
151-
def buildType = android.buildTypes.findByName(variant.buildType.name)
152-
if (buildType != null) {
153-
buildType.configure {
154-
// Check if firebaseCrashlytics extension exists
155-
try {
156-
firebaseCrashlytics {
157-
nativeSymbolUploadEnabled = true
158-
}
159-
appProject.logger.info("RNFirebase: Enabled Crashlytics NDK symbol upload for build type '${variant.buildType.name}'")
160-
} catch (Exception e) {
161-
// Extension might not exist if Crashlytics plugin not applied
162-
appProject.logger.warn("RNFirebase: Could not configure Crashlytics NDK symbol upload for build type '${variant.buildType.name}'. " +
163-
"Ensure the Crashlytics Gradle plugin is applied in your app/build.gradle: ${e.message}")
164-
}
165-
}
166-
}
167-
} catch (Exception e) {
168-
appProject.logger.warn("RNFirebase: Could not configure variant '${variant.name}': ${e.message}")
169-
}
170-
}
171-
}
172-
} catch (Exception e) {
173-
// Fallback: just try to configure the 'release' build type directly
174-
appProject.logger.info("RNFirebase: Using fallback approach for NDK symbol upload configuration")
139+
if (targetAppProject != null) {
140+
try {
141+
def android = targetAppProject.extensions.findByName('android')
142+
143+
if (android != null && android.hasProperty('buildTypes')) {
144+
// Configure all build types that contain 'release' (case insensitive)
145+
android.buildTypes.all { buildType ->
146+
if (buildType.name.toLowerCase().contains('release')) {
175147
try {
176-
android.buildTypes.release {
177-
firebaseCrashlytics {
178-
nativeSymbolUploadEnabled = true
179-
}
180-
}
181-
appProject.logger.info("RNFirebase: Enabled Crashlytics NDK symbol upload for 'release' build type")
182-
} catch (Exception fallbackError) {
183-
appProject.logger.warn("RNFirebase: Could not automatically enable Crashlytics NDK symbol upload. " +
184-
"You may need to configure it manually in your app/build.gradle. " +
185-
"See: https://firebase.google.com/docs/crashlytics/android/get-started-ndk#set-up-automatic-native-symbols-upload")
148+
buildType.ext.set('firebaseCrashlytics', [:])
149+
buildType.firebaseCrashlytics = [
150+
nativeSymbolUploadEnabled: true
151+
]
152+
targetAppProject.logger.info("RNFirebase: Enabled Crashlytics NDK symbol upload for build type '${buildType.name}'")
153+
} catch (Exception e) {
154+
targetAppProject.logger.warn("RNFirebase: Could not automatically configure Crashlytics NDK symbol upload for build type '${buildType.name}'. " +
155+
"You may need to add it manually to your app/build.gradle. See: https://rnfirebase.io/crashlytics/android-setup")
186156
}
187157
}
188158
}
189-
} catch (Exception e) {
190-
appProject.logger.warn("RNFirebase: Failed to configure automatic Crashlytics NDK symbol upload: ${e.message}")
191159
}
160+
} catch (Exception e) {
161+
targetAppProject.logger.warn("RNFirebase: Could not automatically enable Crashlytics NDK symbol upload: ${e.message}")
162+
targetAppProject.logger.info("Please add the following to your android/app/build.gradle:")
163+
targetAppProject.logger.info(" android { buildTypes { release { firebaseCrashlytics { nativeSymbolUploadEnabled true } } } }")
192164
}
193165
}
194166
}

0 commit comments

Comments
 (0)