Thanks to Claude
Now the app is building and working.
I need to integrate this plugins to my project, because i have additional native functions.
/android/app/build.gradle.kts
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
id("com.google.firebase.firebase-perf")
}
Fixed File Example:
build.gradle.kts (46.7 KB)
Added a Issue in Git-Hub
Solar2D/Corona SDK: Fixing “Duplicate Resources” Error with google-services Plugin
Problem Summary
When integrating the Google Services Plugin (com.google.gms.google-services) into a Solar2D/Corona SDK Native Android build, the build fails with duplicate resource errors for all assets, particularly:
resource.car(compiled Lua archive)- iOS-specific files (Icon.png, Images.xcassets, LaunchScreen.storyboardc)
- All Corona assets in the generated assets directory
Error Message:
> Task :app:mergeDebugAssets FAILED
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[...]}
Build Environment:
- Solar2D/Corona SDK Native Android
- Android Gradle Plugin: 8.5.1
- Google Services Plugin: 4.3.15+
- Gradle: 8.7+
Root Cause
The issue occurs because Solar2D’s build system registers the Corona assets directory using:
kotlin
android.sourceSets[name].assets.srcDirs(generatedAssetsDir)
The google-services plugin scans all registered asset source directories during its processing phase. Since the same directory is already part of the asset merge pipeline, it gets registered twice, causing duplicate resource errors.
Additionally, iOS-specific assets that shouldn’t be in Android builds were not being excluded, adding to the duplicate warnings.
Solution
1. Exclude iOS-Specific Assets
In the coronaAssetsCopySpec function, add excludes for iOS files:
kotlin
fun coronaAssetsCopySpec(spec: CopySpec) {
with(spec) {
// ... existing excludes ...
// ✅ Exclude iOS-specific assets (not needed for Android)
exclude("Icon.png") // iOS App Icon
exclude("Images.xcassets/**") // iOS App Icons
exclude("LaunchScreen.storyboardc/**") // iOS Launch Screen
exclude("google-services.json") // Handled by google-services plugin
// ... rest of function ...
}
}
2. Replace srcDirs Registration with Manual Asset Copy
Replace the asset registration code in android.applicationVariants.all:
BEFORE (causes duplicates):
kotlin
android.applicationVariants.all {
// ... taskCopyResources definition ...
mergeAssetsProvider!!.configure {
dependsOn(taskCopyResources)
}
// ❌ This causes duplicate resources with google-services plugin
android.sourceSets[name].assets.srcDirs(generatedAssetsDir)
// ...
}
AFTER (working solution):
kotlin
android.applicationVariants.all {
// ... taskCopyResources definition ...
mergeAssetsProvider!!.configure {
dependsOn(taskCopyResources)
// ✅ Copy assets AFTER the merge process
// This prevents google-services plugin from double-registering the assets
doLast {
copy {
from(generatedAssetsDir)
into(outputDir.get().asFile)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
}
// ❌ DO NOT use srcDirs - causes duplicate resources with google-services
// android.sourceSets[name].assets.srcDirs(generatedAssetsDir)
// Ensure google-services runs AFTER Corona assets are ready
tasks.findByName("process${baseNameCapitalized}GoogleServices")?.mustRunAfter(taskCopyResources)
// ...
}
Why This Works
- Removes duplicate registration: By not using
srcDirs(), we prevent the asset directory from being scanned twice by the google-services plugin - Manual asset integration: The
doLastblock copies assets directly into the merge task’s output directory after all plugin processing is complete - Task ordering:
mustRunAfterensures google-services processes its files before our assets are finalized - iOS asset exclusion: Prevents unnecessary duplicate warnings for platform-specific files
Testing
After implementing this solution:
Build succeeds with google-services plugin enabled
Firebase services work correctly
No duplicate resource errors
resource.car and all Corona assets are properly included in the APK
App runs without crashes
Compatible Plugins
This solution works with:
com.google.gms.google-servicescom.google.firebase.crashlyticscom.google.firebase.firebase-perf- All other Firebase plugins
For Solar2D Team
This appears to be a fundamental incompatibility between Solar2D’s asset management and modern Android Gradle plugins that scan asset directories. Consider:
- Updating the official Android build template with this fix
- Documenting this workaround in the Native Android build documentation
- Investigating whether this can be fixed in the core build system
Related Information
- Google Services Plugin: The Google Services Gradle Plugin | Google Play services | Google for Developers
- Android Asset Merger: https://developer.android.com/studio/build/dependencies