Hilt with multi module not working with aar file - android

I've created a project with one module. e.g
app
module
When I'm using the following code in the app's build.gradle, It's working fine
implementation project(':module')
When I'm creating .aar for module with minifyEnabled true and using it in build.gradle using bellow code
implementation files('module-release.aar')
It gives the following error
Caused by: java.lang.ClassCastException: com.mypackage.DaggerMainApplication_HiltComponents_ApplicationC$ActivityRetainedCImpl$ActivityCImpl cannot be cast to com.com.mypackage.MyActivity_GeneratedInjector

Related

Android aar file Inside a Library module - NoClassDefFoundError

I am having an external library (constants.aar) file. I have kept this .aar file in to my Android library module project's (sdk-module)/lib folder. This sdk-module has classes which uses methods from constants.aar.
Compiling the sdk-module generates sdk-module.aar file.
In my application i am including this sdk-module.aar file. When i am trying to use certain class files of sdk-module, i am getting NoClassDefFoundError.
java.lang.NoClassDefFoundError: Failed resolution of: "class file from constant.aar";
Caused by: java.lang.ClassNotFoundException: Didn't find class "xyz" on path:
I have unzipped the sdk-module.aar file and i can see that constants.aar file is available in its /lib folder.
How to resolve this issue?
android {
defaultConfig {
....
multiDexEnabled true // Add this line in your build.gradle file
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Extend : MultiDexApplication Class In in your ApplicationClass.java
public class BusinessCardApplication extends MultiDexApplication { ... }
OR
MultiDex.install(this); //add this line
Either, See this library's Issues File. If It Is from library's issue there is also define this error detail

com.android.build.api.transform.TransformException: java.lang.RuntimeException: Unable to pre-dex

Facing this issue while I am upgrading my Android project. Upgraded following config till now:
Kotlin v.1.1.60 to v.1.2.41
along with above change I added plugin apply plugin: 'kotlin-kapt' and replaced annotationProcessor to kapt
Upgraded dependency compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" to compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" as I got the warning that "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" was deprecated for new Kotlin version
Uptill now, my project isworking i.e. getting compiled and APK is getting generated. Now I made following changes:
Upgraded Realm from v.2.2.2 to v.5.1.0
At this stage, my project was not getting compiled. For classes such as Realm, RealmResults I was getting 'unresolved reference'. Then I added below code in application's build.gradle
realm {
syncEnabled = true
}
Now 'unresolved reference' is resolved but I am getting above error mentioned in the question.
Caused by: com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/Users/macusername/.android/build-cache/1356d0bbf59bd3c075dd3c13537428b6de3f0678/output/jars/classes.jar' to '/Users/macusername/AndroidProjects/project-name/app/build/intermediates/transforms/dex/flavour-name/debugSIT/folders/1000/10/classes_3ca2264d84fdd4905c647b112b0d3c683ba517e0'

Migrating to Gradle 3.0.0: Error - D8: Program type already present

I am migrating my Android project to Gradle 4.4 and Android Gradle plugin 3.1.2.
It has a library module which depends on parceler library and defines its dependency as follows:
build.gradle of library module:
...
// parceler for serialization (https://github.com/johncarl81/parceler)
implementation "org.parceler:parceler-api:1.0.4"
annotationProcessor "org.parceler:parceler:1.0.4"
...
This seems to compile well and generates my aar file.
Further, my main app module also has a direct dependency on parceler module and contains above lines as dependencies in its build.gradle, along with above aar file.
build.gradle of main app module:
...
api(group: 'com.example.mylibrary', name: 'mylibrary', version: "1.0.7", ext: 'aar') {
transitive = true;
changing = true
}
// parceler for serialization (https://github.com/johncarl81/parceler)
implementation "org.parceler:parceler-api:1.0.4"
annotationProcessor "org.parceler:parceler:1.0.4"
...
Everything works until I try to generate my APK, which fails with the following error.
D8: Program type already present: org.parceler.Parceler$$Parcels$1
Task :MPCApp:transformDexArchiveWithDexMergerForRelease FAILED
When I expand my library project in Android studio, I see Parcels.class under org.parceler package. But it seems similar file is also generated by main app module under the same package which is causing the clash.
Upgrade to the latest (currently 1.1.10) - We got rid of the Parcels generated class.

Facebook Stetho on library project

I've created a library to be released as an aar. In this library I'm using Facebook Stetho so in my library dependencies I'm using:
compile "com.facebook.stetho:stetho:1.4.1"
I've also added the following lines to my library proguard file:
-keep class com.facebook.stetho.** { *; }
-dontwarn com.facebook.stetho.**
After the aar is generated I'm incorporating it on a app using Android Studio File -> New Module -> Import .JAR/.AAR so
compile project(':MyTestProject')
Is added to the app build.gradle file.
When I run the app, the app crashes with the log
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/stetho/Stetho;
....
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.stetho.Stetho" on path:.....
If I add the compile "com.facebook.stetho:stetho:1.4.1" dependency to the app build.gradle is working as expected.
Any idea why?

Freshly imported Android Studio project errors with zxing module

I have been using zxing module as an android library for some time without problems. I have imported my Eclipse project into Android Studio (which I use for everything else!) and the zxing library is added as a module.
In one of my classes in the main module I reference the com.google.zxing.android.client.Intents class which is in the zxing module. I can write code in Android studio and these references have the correct imports selected.
When I run a gradlew clean build I am getting messages saying 'cannot find symbol class Intents'.
In settings.gradle I have includes for both my main module and the zxing module.
In the build.gradle of my main module I have 'compile project(':zxing'). These were both added during the import from Eclipse. I can also see that the zxing module is being built as part of the gradlew clean build.
I have tried deleting the zxing module and references then trying to add it manually. I have compared the way that this module is implemented to another project with a similar module that works. All looks fine.
Is anyone able to make a suggestion?
Edit:
settings.gradle file
include ':app'
include ':captureActivity'
build.gradle of main module
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.wigglyamps.littlegreenbutton"
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':captureActivity')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
Java class file in main module
public class test {
public void hello () {
String i = Intents.Scan.ACTION;
}
}
I don't really know the zxing framework, but have you tried to use the maven artifact instead of referencing a module?
If you want to use the artifact add this to the dependencies of the project/module that uses zxing: compile 'com.google.zxing:core:3.1.0'
Edit: You said you imported the project from eclipse; I'm in the middle of transitioning to gradle and the import function hardly produces anything useful if the eclipse project contained references to library projects (not jar's). I rebuild my projects from scratch by creating a new app(with modules) in Android Studio and copy/paste code and resources into the new app's directories

Categories

Resources