I have a project and recently we converted the project to a multi module. However I could not run the module it gives me this error.
I think I made something wrong with the dependencies and some configurations.
Following is my app/build.gradle
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'com.google.protobuf'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlin-android-extensions'
}
apply plugin: 'kotlin-android'
android {
compileSdk 33
defaultConfig {
minSdk 26
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
dataBinding true
}
packagingOptions{
pickFirst "androidsupportmultidexversion.txt"
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
hilt {
enableAggregatingTask = true
}
namespace '##.###.########.###############'
}
dependencies {
def lifecycle_version = "2.5.1"
def roomVersion = "2.4.3"
def nav_version = "2.5.3"
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
implementation 'androidx.multidex:multidex:2.0.1'
// UI Tests
androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.2.1'
//Material Design
implementation 'com.google.android.material:material:1.6.1'
def fragments_version = "1.5.2"
implementation "androidx.fragment:fragment-ktx:$fragments_version"
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
// ViewModel utilities for Compose
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
// Lifecycles only (without ViewModel or LiveData)
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version")
// Annotation processor
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
// To use Kotlin annotation processing tool (kapt)
implementation("androidx.room:room-runtime:$roomVersion")
kapt("androidx.room:room-compiler:$roomVersion")
// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$roomVersion")
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.2")
// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"
//Criptografia
implementation 'com.madgag.spongycastle:bctls-jdk15on:1.58.0.0'
//AWS SDK for Android
implementation 'com.amazonaws:aws-android-sdk-core:2.51.0'
implementation 'com.amazonaws:aws-android-sdk-auth-core:2.51.0'
implementation 'com.amazonaws:aws-android-sdk-iot:2.36.0'
implementation 'com.amplifyframework:aws-auth-cognito:1.37.1'
implementation 'com.jcraft:jsch:0.1.55'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation "androidx.compose.ui:ui:1.2.1"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
// Coil
implementation "io.coil-kt:coil-compose:1.4.0"
//Protobuf
apply plugin: 'com.google.protobuf'
implementation 'com.google.protobuf:protobuf-lite:3.0.0'
//Barber
implementation("app.cash.barber:barber:0.3.3")
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
// G800 Lib
implementation(name: 'libgedi-0.190121.gpos800', ext:'aar')
implementation(name: 'SatGerLib', ext: 'aar')
//Dagger Hilt
implementation 'com.google.dagger:hilt-android:2.43.2'
kapt 'com.google.dagger:hilt-compiler:2.43.2'
implementation 'com.airbnb.android:lottie:3.4.0'
implementation ('io.socket:socket.io-client:2.0.1') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}
implementation 'com.loopj.android:android-async-http:1.4.11'
//Encryption
implementation "androidx.security:security-crypto:1.0.0"
//UNZIP
implementation "org.apache.commons:commons-compress:1.21"
implementation "androidx.core:core-ktx:+"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//GPS
implementation 'com.google.android.gms:play-services-location:18.0.0'
//QR CODE GENERATOR
implementation 'com.google.zxing:core:3.4.1'
//Gson
implementation 'com.google.code.gson:gson:2.9.1'
/* Retrofit */
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$okHttpInterceptorVersion"
implementation "com.squareup.retrofit2:converter-scalars:2.4.0"
implementation 'com.android.support:multidex:1.0.3'
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite { }
}
}
}
}
repositories {
mavenCentral()
}
And this one is dev/build.gradle
(submodule)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlin-android-extensions'
}
android {
namespace 'br.com.###.dev'
compileSdk 33
defaultConfig {
applicationId "br.com.###.dev"
minSdk 26
targetSdk 33
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions{
pickFirst "androidsupportmultidexversion.txt"
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
hilt {
enableAggregatingTask = true
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation project(':app')
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation(name: 'libgedi-0.190121.gpos800', ext:'aar')
implementation(name: 'SatGerLib', ext: 'aar')
implementation 'com.google.dagger:hilt-android:2.43.2'
kapt 'com.google.dagger:hilt-compiler:2.43.2'
}
And this is the top level build.gradle
file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.7.0'
repositories {
google()
mavenCentral()
maven { url='https://jitpack.io'}
}
ext {
compose_version = '1.2.1'
/* Http */
retrofitVersion = "2.9.0"
okHttpVersion = "4.10.0"
okHttpInterceptorVersion = "4.10.0"
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20'
classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.7.20"
classpath "com.apollographql.apollo:apollo-gradle-plugin:2.4.6"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.44.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
flatDir {
dirs 'libs'
}
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app\src\main\java\packagename\MyApplication.kt
@HiltAndroidApp
class MyApplication: Application()
I can post other files if you need to see. Now I did not want to make it look complicated. Any help will be appreciated. Thanks in advance.
As I wrote in my comment, first I updated libraries so they match in all build.gradle files. In this case it gave another error. Then I opened an issue to dagger github repo and they answered like this:
Application class annotated with @HiltAndroidApp has to be defined in an android application project
This means that your @HiltAndroidApp annotated class is currently defined in a library module (i.e. a build.gradle file with plugins { id 'com.android.library' }, which is not allowed. Instead, you need to move that class into the application module (i.e. a build.gradle file with plugins {id 'com.android.application'}.
So lastly we moved the application class to module dev and also we put an application class inside of the library module too but we did not add @HiltAndroidApp. So it looks like this (library module):
class MyApplication
And application module:
@HiltAndroidApp
class MyApplication: Application()
And obviously we adjusted manifest files too. Also we got several errors too but we fixed them by searching from google. Key part was adding hilt application class inside of the dev/module. I hope it helps who has similar issues.