Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27758] Android: Modules with AARs in "lib" directory should trigger a build failure in 9.0.0

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2020-02-14T20:58:38.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.0.0
ComponentsAndroid
Labelsaar, android, breaking-change, build, dependencies, gradle, module
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-02-11T05:10:34.000+0000
Updated2021-09-28T02:52:03.000+0000

Description

*Summary:* The Android gradle build system allows a library project to reference a local AAR for compilation, but it won't merge the local AAR's classes, "AndroidManifest.xml", assets, or "res" files into the library project's built AAR. This is intentional on Google's end. The build system will only merge all of the AAR files' content into an app project. Because of the above, a native module referencing local AAR files will crash at runtime when built with Titanium 9.0.0 and gradle. It will compile fine, but the classes in the AARs will not be included in the module; nor the app. *Solution:* When building a native Android module with Titanium, the CLI should trigger a build failure if the module's "lib" directory contains any AAR files and should tell the developer to reference AAR libraries via the "build.gradle" file instead. *Note:* This is a breaking-change. But by doing this, we force module developers to reference dependencies the gradle/maven way, which will solve library version conflict issues between modules.

Comments

  1. Joshua Quick 2020-02-12

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11472
  2. Joshua Quick 2020-02-12

    PR (9.0.x): https://github.com/appcelerator/titanium_mobile/pull/11474
  3. Christopher Williams 2020-02-13

    merged to master and 9_0_X, for 9.0.0 release
  4. Lokesh Choudhary 2020-02-14

    Verified the fix with SDK 9.0.0.v20200214090043. Closing.
  5. Prashant Saini 2021-09-27

    I believe an example would have been better either here or in docs for below use-case: - How to add AAR/JAR files which are not present on central sites to be added directly in .gradle file. There are multiple instances where projects use private/closed-source AAR and cannot be uploaded on gradle sites. There are online posts which shows how to do it for native Android projects, but finding the same solution for Titanium Android module structure is not an easy way yet.
  6. Joshua Quick 2021-09-27

    bq. There are online posts which shows how to do it for native Android projects, Those "native" solutions work for Titanium as well. You would have to copy the private AAR to both the module project and the app project. The issue is nobody like this solution. Not even in a native Android Studio project. Again, this is not a Titanium issue. We're using Google's native gradle build system and it has the same limitations. I'll state this again... when a native AAR project (such as your Titanium module project) references a "local" AAR as a dependency, Google's gradle build system will "link" to the AAR, but it won't "merge" the 2 AARs together. The merging of AARs into a single binary only happens when you build an app project. This is how Google's gradle build system works. So, when you look at native solutions online, notice they always force you to reference the private AAR as well as their AAR which depends on it.
  7. Joshua Quick 2021-09-27

    Here's a followup on how to use a private AAR with your module project and app project. Note that you have to add it to "both" projects. In your module project, create a "lib-private" folder and copy your private AAR there. ./<ModuleName>/android/lib-private Set up your module's "build.gradle" file to link to the above "lib-private" folder containing your AAR. Now when you build your module, it will "link" to this private AAR at compile time, but it won't merge the private AAR into your module's built AAR. Note that if your private AAR has any public gradle dependencies, they need to be duplicated in your module's "build.gradle" because dependency info is not stored in an AAR file. ./<ModuleName>/android/build.gradle
       // build.gradle
       dependencies {
       	implementation fileTree(dir: "${projectDir}/../../lib-private", include: ['*.aar'])
       }
       
    For the app project, you must also copy the private AAR to the following folder when using your module. Note that Titanium app projects will always include whatever libraries (JARs and AARs) that are in this folder when building your app. The key thing here is Google's build system does "merge" all AARs into the app's binary. ./platform/android
  8. Prashant Saini 2021-09-28

    Thanks for the detailed explanation. For the app project, do we have to put private AAR files at this location: *"project-root-folder/app/platform/android/"* or any other location? I honestly think that such deeply hidden info must be available at Guide docs site with example like above showing clearly the folder structure.

JSON Source