Skip to content

Android Native Build and com.google.gms.google-services + Solution #847

@KaiKoeh

Description

@KaiKoeh

Native Android Build, it will not building when this Plugin added:

Used Android Build Template from Corona-3723

build.gradle.kts:

plugins {
    id("com.android.application")
    id("com.google.gms.google-services")  // ← This causes the issue
}

The build will thrown:

Task :app:mergeDebugAssets FAILED
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[...]}

Fixed File Example:
build.gradle.kts.zip

The more detailed info & solution is here:
Forum Thread

Additional INFO:

// ============================================================================
// GOOGLE-SERVICES PLUGIN FIX - DUPLICATE RESOURCES WORKAROUND
// ============================================================================
//
// PROBLEM: The google-services plugin causes "Duplicate resources" build errors
// when integrated with Solar2D/Corona SDK Native Android builds.
//
// ROOT CAUSE: The google-services plugin scans all registered asset directories
// during its processing phase. Since Solar2D registers the Corona assets directory
// using srcDirs(), it gets registered twice, causing duplicate resource errors.
//
// CHANGES MADE TO FIX THIS ISSUE:
//
// 1. LINE ~264 - coronaAssetsCopySpec() function:
// Added excludes for iOS-specific files that shouldn't be in Android builds:
// - Icon.png (iOS App Icon)
// - Images.xcassets/** (iOS App Icons)
// - LaunchScreen.storyboardc/** (iOS Launch Screen)
// - google-services.json (processed by google-services plugin)
//
// 2. LINE ~351-364 - android.applicationVariants.all block:
// CRITICAL CHANGES:
// a) REMOVED: android.sourceSets[name].assets.srcDirs(generatedAssetsDir)
// This line caused the duplicate registration with google-services plugin
//
// b) ADDED: doLast block in mergeAssetsProvider.configure
// Manually copies assets AFTER the merge process completes
// This prevents double-registration by google-services plugin
//
// c) ADDED: mustRunAfter for google-services task ordering
// Ensures google-services runs after Corona assets are ready
//
// RESULT:
// ✅ Build succeeds with google-services plugin enabled
// ✅ Firebase services work correctly
// ✅ No duplicate resource errors
// ✅ resource.car and all Corona assets properly included in APK
// ✅ App runs without crashes
//
// Compatible with:
// - com.google.gms.google-services
// - com.google.firebase.crashlytics
// - com.google.firebase.firebase-perf
// - All other Firebase plugins
//
// For more details, see Solar2D forum post about this fix.
// ============================================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions