Dagger build error - java

I've got two objects which I inject with dagger2 without any problems. When I add third one (the same way like two before), project does not rebuild and gives errors, that points into first two (nothing here about added third one):
error: com.google.firebase.database.DatabaseReference cannot be provided without an #Inject constructor or from an #Provides- or #Produces-annotated method.
com.google.firebase.database.DatabaseReference is injected at
com.hotmail.at.jablonskimichal.dni.wolne.od.handlu.ui.splash.SplashPresenter.freeDaysCloudReference
com.hotmail.at.jablonskimichal.dni.wolne.od.handlu.ui.splash.SplashPresenter is injected at
com.hotmail.at.jablonskimichal.dni.wolne.od.handlu.providers.components.MainPresenterComponent.inject(destination)
Every three modules and components are implemented in the same way. Of course when I delete added third one, projects compiles easily.
Module which messes project build:
#Module
public class MainPresenterModule {
private final MainPresenter presenter;
public MainPresenterModule(MainPresenter presenter) {
this.presenter = presenter;
}
#Singleton
#Provides
MainPresenter provideMainPresenter() {
return presenter;
}
}
Component:
#Singleton
#Component(modules = {MainPresenterModule.class})
public interface MainPresenterComponent {
void inject(SplashPresenter destination);
}
Maybe useful:
I am using those libraries for DI with dagger2:
implementation 'com.google.dagger:dagger-android:2.11'
implementation 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
with newest android studio (3.1.1) and gradle (3.1.1) on mac osx. Of course I've tried invalidating cache and restarts, cleans etc. I've checked imports and all of them are the same.
Edit:
When I remove usage of injection
#Inject
DatabaseReference shopsCloudReference;
public MainPresenter(MainController controller) {
super(controller);
Core.injectShopsComponent().into(this);
}
And
#Inject
DatabaseReference freeDaysCloudReference;
public SplashPresenter(SplashController controller) {
super(controller);
Core.injectFreeDaysComponent().into(this);
}
project compiles, but it is not what I wanted.
EDIT
There's lot of answers that I didn't add firebase libs in gradle. My full gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.hotmail.at.jablonskimichal.dni.wolne.od.handlu"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
allprojects {
repositories {
mavenCentral()
google()
maven { url "https://jitpack.io" }
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//tests
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//support
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
//images loading
implementation 'com.github.bumptech.glide:glide:4.4.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'
//network
implementation 'com.squareup.okhttp3:okhttp:3.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.2.0'
//json parsing
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.google.code.gson:gson:2.8.0'
//for view bindings
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//rxjava
def rxVersion = '2.0.2'
implementation "io.reactivex.rxjava2:rxandroid:$rxVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxVersion"
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
//dagger
implementation 'com.google.dagger:dagger-android:2.11'
implementation 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
//google
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.firebase:firebase-database:15.0.0'
implementation 'com.google.firebase:firebase-core:15.0.0'
//datetime
implementation group: 'joda-time', name: 'joda-time', version: '2.9.9'
//transitions
implementation "com.andkulikov:transitionseverywhere:1.7.9"
//kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'

Well, you wrote :
#Component(modules = {MainPresenterComponent.class})
It should be :
#Component(modules = {MainPresenterModule.class})

Related

Android studio: cannot access MenuHost class file for androidx.core.view.MenuHost not found

I've got an error while building my project. This is my error message: cannot access MenuHost
class file for androidx.core.view.MenuHost not found.
I didn't find any solution for this problem. I would be very happy if you could help me.
I've got this error for an empty Activity:
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class CallActivity extends AppCompatActivity {
/* Access modifiers changed, original: protected */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.activity_call);
}
}
This is my build.gradle (app):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.ghostcontact"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy {
force 'androidx.core:core:1.6.0'
force 'androidx.core:core-ktx:1.6.0'
}
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-storage:20.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.hbb20:ccp:2.3.1'
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.firebase:firebase-core:20.0.0'
implementation 'com.google.firebase:firebase-crashlytics:18.2.4'
implementation 'com.google.firebase:firebase-analytics:20.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'commons-validator:commons-validator:1.6'
implementation 'com.airbnb.android:lottie:3.4.0'
//OTP PIN View Design
implementation 'com.chaos.view:pinview:1.4.3'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.core:core:1.6.0'
implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.activity:activity:1.4.0'
implementation 'androidx.activity:activity-compose:1.4.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
}
And my build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven{url 'https://maven.fabric.io/public'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{url 'https://jitpack.io'}
maven{url 'https://dl.bintray.com/tapsellorg/maven'}
maven{url 'https://maven.google.com/'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Had the same problem. Fixed the issue by removing this lines:
configurations.all {
resolutionStrategy { force 'androidx.core:core:1.6.0' }
}
under defaultConfig of build.gradle(:app)
I also do not know the source/reason behind the error as well.
In the build.gradle i changed this:
configurations.all {
resolutionStrategy { force 'androidx.core:core:1.6.0' }
}
to this:
configurations.all {
resolutionStrategy { force 'androidx.core:core:1.7.0' }
}
and this worked for me.
MenuHost was added in androidx.core:core:1.7.0 and above.
https://developer.android.com/jetpack/androidx/releases/core#1.7.0-alpha02
Just upgrade your dependencies.
Just add in you dependencies:
implementation 'androidx.core:core:{latest version}' // 1.7.0 or above
I had exact same situation - changing "extends AppCompatActivity" to "extends Activity" fixed the issue.
Edit: I don't know the source/reason behind that error, sadly...
For me it worked when I manually cast it to MenuHost:
private lateinit var menuHost: MenuHost
override fun onAttach(context: Context) {
super.onAttach(context)
menuHost = (requireActivity() as MenuHost)
}
If this does not work, manually specifying the module you want to use should fix it. In the project build.gradle file you have to add this:
allprojects {
...
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module("androidx.activity:activity:1.0.0") using module("androidx.activity:activity:$libVersions.activity")
substitute module("androidx.fragment:fragment:1.1.0") using module("androidx.fragment:fragment:$libVersions.fragment")
substitute module("androidx.core:core:1.2.0") using module("androidx.core:core:$libVersions.core")
substitute module("androidx.core:core-ktx:1.2.0") using module("androidx.core:core-ktx:$libVersions.core")
}
}
}
}
(Double check what version you have in your project that affects you, in my case I noticed 1.00 for activity, 1.1.0 for fragment and 1.2.0 for core - they could be different in your case, you need to check the list of dependencies of your project)
And you can use it directly as:
private lateinit var menuHost: MenuHost
override fun onAttach(context: Context) {
super.onAttach(context)
menuHost = requireActivity()
}

Cannot access class 'java.lang.String'. Check your module classpath for missing or conflicting dependencies

I was setting up a java/kotlin library for my android project in which i was creating a data class (model) with moshi converter. But the issue is the annotation #JsonClass and at other places i am getting this error
Cannot access class 'java.lang.String'. Check your module classpath for missing or conflicting dependencies
The Data class
The data class image
The error shown by IDE
The library gradle code
plugins {
id 'java-library'
id 'kotlin'
id 'kotlin-kapt'
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
implementation "com.squareup.moshi:moshi:1.12.0"
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.12.0"
}
And the app level build.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.1.0-alpha01'
kotlin_version = '1.5.21'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
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
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app level gradle code
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.composeappname"
minSdk 23
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.tests.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation project(":libmynetworklibrary")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.tests.ext:junit:1.1.3'
androidTestImplementation 'androidx.tests.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-tests-junit4:$compose_version"
}

Dagger generating duplicate `XXXDialogFragment_MembersInjector` classes in Android app (Program type already present)

I have a BaseDialogFragment that uses dependency injection with Dagger, and then I have two different modules that subclass the BaseDialogFragment.
When attempting to build I'm getting the following error:
> Task :app:transformClassesWithDexBuilderForDevelopmentDebug
AGPBI: {"kind":"error","text":"Program type already present: BaseDialogFragment_MembersInjector","sources":[{}],"tool":"D8"}
> Task :app:transformDexArchiveWithDexMergerForDevelopmentDebug FAILED
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
I've searched my project and it appears that there are only two different BaseDialogFragment_MembersInjector classes being generated: one in each respective module.
I have already:
Cleaned the project
Deleted the generated duplicate class
Invalidated caches and restarted
Updated Dagger version
Ensured that multidexEnabled is set to true
Added unnecessary #inject field on base class per recommendation found here
android.gradle:
android {
compileSdkVersion "$android_compile_version".toInteger()
defaultConfig {
minSdkVersion "$android_min_sdk".toInteger()
targetSdkVersion "$android_target_sdk".toInteger()
versionCode = 1
versionName = "1.0"
manifestPlaceholders = rootProject.ext.manifestPlaceholders
renderscriptTargetApi 17
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
packagingOptions {
exclude "META-INF/DEPENDENCIES"
exclude "META-INF/NOTICE"
exclude "META-INF/LICENSE"
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE.txt"
exclude "META-INF/maven/com.google.guava/guava/pom.properties"
exclude "META-INF/maven/com.google.guava/guava/pom.xml"
exclude "LICENSE.txt"
exclude ".readme"
}
signingConfigs {
debug {
storeFile file("${rootProject.projectDir}/keystores/debug.keystore")
}
release {
storeFile file("/opt/android-keystore/youversion.keystore")
storePassword "youversion"
keyAlias System.getenv("CERT_USER")
keyPassword System.getenv("CERT_PASS")
}
}
buildTypes {
debug {
debuggable true
minifyEnabled false
testCoverageEnabled coverage
if (project.name == "app") {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
testProguardFiles getDefaultProguardFile("proguard-android.txt"), "test-proguard-rules.pro"
}
multiDexKeepProguard file("${rootProject.projectDir}/config/proguard/test-proguard-keep.pro")
signingConfig signingConfigs.debug
ext.enableCrashlytics = false
matchingFallbacks = ['release']
}
release {
debuggable false
minifyEnabled project.name == "app"
shrinkResources project.name == "app"
if (project.name == "app") {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
signingConfig signingConfigs.release
}
}
testOptions {
animationsDisabled true
}
dataBinding {
enabled true
}
lintOptions {
lintConfig file("$rootProject.projectDir/config/lint/default.xml")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
useLibrary "org.apache.http.legacy"
}
dependencies.gradle:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines"
if (project.parent?.name == "modules" && project.name != "base") {
implementation project(":modules:base")
}
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.0-LC2") {
exclude group: "org.jetbrains.kotlin"
}
// brotli
implementation "org.brotli:dec:$brotli_version"
// wire
implementation "com.squareup.wire:wire-runtime:2.3.0-RC1"
// arch
implementation "android.arch.lifecycle:extensions:$app_arch_version"
implementation "android.arch.persistence.room:runtime:$app_arch_version"
// flurry
implementation "com.flurry.android:analytics:$flurry_version#aar"
// proto
implementation("youversion.android:protobuf:$bible_proto_version#aar") {
exclude group: "com.google.code.findbugs"
exclude group: "com.squareup.okio"
exclude group: "com.squareup.okhttp3"
exclude group: "com.google.android.gms"
exclude group: "com.facebook.android"
exclude group: "com.android.support"
exclude group: "com.github.bumptech.glide"
exclude group: "com.google.firebase"
exclude group: "com.android.databinding"
exclude group: "com.google.dagger"
exclude group: "android.arch.lifecycle"
exclude group: "android.arch.persistence.room"
}
// nuclei
api("nuclei.android:nuclei-android:$nuclei_version") {
exclude group: "com.android.support"
exclude group: "com.google.android.gms"
exclude group: "com.google.android.exoplayer"
exclude group: "com.squareup.okhttp3"
}
api("nuclei3.android:nuclei-android:$nuclei3_version") {
exclude group: "com.android.support"
exclude group: "com.google.android.gms"
exclude group: "com.google.android.exoplayer"
exclude group: "com.squareup.okhttp3"
}
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
androidTestImplementation("com.squareup.okhttp3:mockwebserver:$okhttp_version") {
exclude group: "com.android.support", module: "multidex"
}
implementation "com.squareup.sqldelight:android-driver:$sqldelight_version"
implementation "com.android.support:multidex:$support_multidex_version"
// play services
implementation "com.google.android.gms:play-services-auth:$play_services_auth_version"
implementation "com.google.android.gms:play-services-maps:$play_services_maps_version"
implementation "com.google.android.gms:play-services-cast-framework:$play_services_cast_version"
implementation "com.google.android.gms:play-services-base:$play_services_base_version"
// android support libraries
implementation "com.android.support:appcompat-v7:$support_lib_version"
implementation "com.android.support:support-v4:$support_lib_version"
implementation "com.android.support:design:$support_lib_version"
implementation "com.android.support:cardview-v7:$support_lib_version"
implementation "com.android.support:recyclerview-v7:$support_lib_version"
implementation "com.android.support:gridlayout-v7:$support_lib_version"
implementation "com.android.support:palette-v7:$support_lib_version"
implementation "com.android.support:customtabs:$support_lib_version"
implementation "com.android.support:mediarouter-v7:$support_lib_version"
implementation "com.android.support:support-dynamic-animation:$support_lib_version"
implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"
implementation "com.android.support:preference-v14:$support_lib_version"
// firebase
implementation "com.google.firebase:firebase-messaging:$firebase_messaging_version"
implementation "com.google.firebase:firebase-invites:$firebase_invites_version"
implementation "com.google.firebase:firebase-appindexing:$firebase_app_indexing_version"
implementation "com.google.firebase:firebase-perf:$firebase_perf_version"
// appboy
//implementation files("libs/appboy-mini.jar")
implementation "com.appboy:android-sdk-base:$appboy_version#aar"
// apps flyer
implementation "com.appsflyer:af-android-sdk:$apps_flyer_version#aar"
// glide image library
implementation ("com.github.bumptech.glide:glide:$glide_version") {
exclude group: "com.android.support"
}
// glide okhttp module
implementation ("com.github.bumptech.glide:okhttp-integration:$glide_version") {
exclude group: "com.squareup.okhttp3", module: "okhttp"
}
// facebook support libraries
implementation "com.facebook.android:facebook-android-sdk:$facebook_version"
// crashlytics
implementation("com.crashlytics.sdk.android:crashlytics:$crashlytics_version#aar") {
transitive = true
}
// dagger
implementation("com.google.dagger:dagger:$dagger_version") {
exclude group: "com.google.code.findbugs"
}
implementation("com.google.dagger:dagger-android:$dagger_version") {
exclude group: "com.google.code.findbugs"
}
implementation("com.google.dagger:dagger-android-support:$dagger_version") {
exclude group: "com.google.code.findbugs"
}
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
// arch apt
kapt "android.arch.lifecycle:compiler:$app_arch_version"
kapt "android.arch.persistence.room:compiler:$app_arch_version"
// branch
implementation "io.branch.sdk.android:library:$branch_version"
// Testing-only dependencies
androidTestImplementation project(":modules:tests")
androidTestImplementation "androidx.test:core:$android_test_core"
androidTestImplementation "androidx.test:runner:$android_test_runner"
androidTestImplementation "androidx.test.espresso:espresso-core:$android_espresso_core"
}
I've also taken a look at this issue here — not sure if it's related, but it sounds similar.
Can anyone tell me what's going on here? Thanks for the help.
You have your BaseDialogFragment_MembersInjector generated multiple times actually, for each of your sub-modules, as described. And there is a collision while assembling the topmost :app module. Clean or delete build/ directories and recreating them won't help actually.
What you should do is to extend your BaseDialogFragment, say, making SimpleBaseDialogFragment extends BaseDialogFragment in :base module (near BaseDialogFragment).
Then you must add some dummy #Inject-annotated field to it (to force Dagger to generate single _MembersInjector in :base rather than in sub-modules).
And then extend any further dialog-fragments from that SimpleBaseDialogFragment, then clear and rebuild project.
For example (in Kotlin):
class DummyInjectableField #Inject constructor() {}
class SimpleBaseDialogFragment : BaseDialogFragment() {
#Inject lateinit var dummy: DummyInjectableField
}
This is just a workaround, and this helped in my case.
Please, see explanation here: https://github.com/google/dagger/issues/955

java.lang.NoSuchMethodError: No static method - Firebase issue despite not using FirebaseMessagingService?

So I'm using Firebase to get my app analytics but my users have been reporting crashes which I couldn't re-create (the crash) in any of my test devices.
I wrote a bug reporting library within my app which would send me the verbose logs via email and found out the main cause.
Surprisingly, I am not even using FirebaseMessagingService in my app so would like to know if someone can help me out here? Tried searching for the solution but couldn't find it so creating a thread here.
Here's the log:
ava.lang.NoSuchMethodError: No static method zzad()Lcom/google/firebase/iid/zzan; in class Lcom/google/firebase/iid/zzan; or its super classes (declaration of 'com.google.firebase.iid.zzan' appears in /data/app/com.myapp.myapp-1/base.apk:classes2.dex)
at com.google.firebase.messaging.FirebaseMessagingService.zzb(Unknown Source)
at com.google.firebase.iid.zzb.onStartCommand(Unknown Source)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3770)
at android.app.ActivityThread.-wrap23(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6816)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
My build.gradle:
apply plugin: 'com.android.application'
//apply plugin: 'com.google.android.gms.oss-licenses-plugin'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myapp.myapp"
minSdkVersion 18
targetSdkVersion 28
multiDexEnabled true
resConfigs "en"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dexOptions {
jumboMode true
}
}
repositories {
google()
flatDir {
dirs 'libs'
}
maven {
url "https://jitpack.io"
}
jcenter()
}
dependencies {
implementation 'com.devbrackets.android:exomedia:4.0.3'
// Radio
implementation 'com.google.android.exoplayer:exoplayer:r2.4.3'
implementation 'com.cleveroad:audiovisualization:1.0.1'
implementation 'com.google.code.gson:gson:2.8.5'
// General
implementation 'org.jsoup:jsoup:1.11.2'
implementation 'com.onesignal:OneSignal:3.10.6'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.duolingo.open:rtl-viewpager:1.0.2'
implementation 'com.github.chrisbanes:PhotoView:1.3.1'
implementation 'com.android.support:multidex:1.0.3'
// Google Support Libraries
implementation 'com.android.support:multidex-instrumentation:1.0.3'
implementation "com.android.support:exifinterface:$supportlib_version"
implementation "com.android.support:cardview-v7:$supportlib_version"
implementation "com.android.support:appcompat-v7:$supportlib_version"
implementation "com.android.support:recyclerview-v7:$supportlib_version"
implementation "com.android.support:design:$supportlib_version"
implementation "com.android.support:support-v4:$supportlib_version"
implementation "com.android.support:support-core-utils:$supportlib_version"
implementation "com.android.support:support-media-compat:$supportlib_version"
implementation "com.android.support:customtabs:$supportlib_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// Google Services
implementation "com.google.android.gms:play-services-oss-licenses:$gps_version"
implementation "com.google.android.gms:play-services-gcm:$gps_version"
implementation "com.google.android.gms:play-services-ads:$gps_version"
implementation files('libs/YouTubeAndroidPlayerApi.jar')
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.3'
// Flurry Analytics
implementation 'com.flurry.android:analytics:11.6.0#aar'
// About Fragment
implementation project(':library')
implementation project(':crashlib')
// Easyrest Library
implementation('com.github.fcopardo:easyrest:v1.4.2#aar') {
transitive = true
}
// ta4j for technical analysis
implementation 'org.ta4j:ta4j-core:0.11'
// display libraries
implementation 'com.github.florent37:fiftyshadesof:1.0.0'
// retrofit for quick and safe network communication
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.github.faruktoptas:RetrofitRssConverterFactory:0.0.2'
// RxJava for multithreaded network requests with retrofit
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
// PriceChart Library
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
// Okhttp And Logging
implementation 'com.squareup.okhttp3:okhttp:3.14.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
// Custom font lib
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
// Material Dialogs - Sort By Menu
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
// Toggle Button - Currency Card
implementation 'com.nex3z:toggle-button-group:1.1.2'
// Favrorite Button - Star
implementation 'com.github.ivbaranov:materialfavoritebutton:0.1.5'
// Bottom Dialog Sheet
implementation 'com.github.marcoscgdev:DialogSheet:1.0.5'
// Intro Lib
implementation 'agency.tango.android:material-intro-screen:0.0.5'
implementation 'com.jakewharton.threetenabp:threetenabp:1.2.0'
}
apply plugin: 'com.google.gms.google-services'
// Work around
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
Project gradle:
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
maven {
url 'https://jitpack.io'
}
}
}
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
//classpath 'com.google.android.gms:oss-licenses-plugin:0.9.4'
}
repositories {
google()
maven {
url 'https://maven.google.com/'
}
jcenter()
}
}
ext {
supportlib_version = '28.0.0'
gps_version = '[16.0.0, 17.0.0)'
fb_version = '[15.0.0, 17.0.0)'
archRoomVersion = "1.0.0"
}
//Ensure that all dependencies use the same version of the Android Support library
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')) {
details.useVersion "$supportlib_version"
}
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex')) {
details.useVersion "$gps_version"
}
if (details.requested.group == 'com.google.firebase'
&& !details.requested.name.contains('multidex')) {
details.useVersion "$fb_version"
}
}
}
}
allprojects {
repositories {
google()
jcenter()
}
}
Thanks in advance!
This is likely to be caused by a conflict of different versions of library dependencies between the compiled and runtime version of your library/app. It could be that one of your other dependencies depends on an older version of FCM or other libraries. Basically, your project is probably depending on different versions of a same library.
As Martin mentioned in his answer, remove the version check and the exact conflict should be shown in the log if you compile again, then you can resolve it very easily.
remove this line (it causes more problems than it would solve - it only hides the problems):
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
the dependencies should look alike this (ads and gcm are now below com.google.firebase):
// Google Services
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.android.gms:play-services-auth:16.0.1"
// implementation "com.google.android.gms:play-services-ads:17.2.0"
// Firebase
implementation "com.google.firebase:firebase-core:16.0.8"
implementation "com.google.firebase:firebase-messaging:17.5.0"
implementation "com.google.firebase:firebase-ads:17.2.0"
of course, this would also require name-space changes in code, as well as migrating from GCM to FCM, but this migration would definitely be sooner or later be due, to to GCM being shut down.

Could not find method implementation() for arguments [directory 'libs'] on object

Error Message:- Could not find method implementation() for arguments [directory
'libs'] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Code
apply plugin: 'com.android.application'
ext {
supportVersion='27.1.1'
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.eassycars.www.dlservices"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildscript {
repositories {
jcenter()
}
configure(':app') {
dependencies {
classpath 'com.android.tools.build.gradle:4.8.1'
implementation fileTree (include: ['*.jar'], dir: 'libs')
implementation "com.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler :$supportVersion"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:palette-v7:$supportVersion"
implementation "com.android.support:customtabs:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation 'com.google.android.exoplayer:exoplayer:r2.0.4'
// utils
implementation 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.github.Commit451:bypasses:1.0.4'
implementation 'com.jakewharton:butterknife:8.8.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.0'
implementation 'com.drewnoakes:metadata-extractor:2.9.1'
implementation 'com.orhanobut:hawk:2.0.1'
classpath 'com.google.gms:google-services:3.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
}}
}
}
I updated the "distributionUrl in my "gradle/wrapper/gradle-wrapper.properties" file to match the current gradle version.
I also updated the classpath in my top level build.gradle file to match the gradle API level.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
Re-synced and then it built OK.
Because you have incorrect block in your build.gradle. Looks like you're mixing top level build.gradle and module build.gradle. Your app module build.gradle should be something like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
...
}
buildTypes {
release {
...
}
}
..
}
dependencies {
...
}
please visit Configure your build for details.
Remove the space between version:
implementation "com.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler:$supportVersion"
Also, please move the dependencies block out of the android block:
android {
...
}
...
dependencies{
...
}

Categories