No static method decodeBase64 - Google Credential - java

I built an Android application with a service account on it to upload files on Google Drive, which works perfectly on the emulator and Android Nougat. Now, I tried it on a Samsung Galaxy Tab A with Android 8.1 and before implementing the service account everything worked fine. Now, when I try to save a file on google Drive from it, I get the error:
java.lang.NoSuchMethodError: No static method decodeBase64(Ljava/lang/String;)[B in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
The problematic code is where I log in, in particular in the fromStream method:
private Credential authorize () throws IOException {
InputStream in = getAssets().open("credentials.json");
return GoogleCredential.fromStream(in)
.createScoped(Collections.singleton(DriveScopes.DRIVE_FILE));
}
These are the new libraries implemented, I add commons-codec:commons-codec:1.15 since I read that it can be caused by it but it still doesn't work:
//API Google Drive
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation('com.google.api-client:google-api-client-android:1.26.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
// https://mvnrepository.com/artifact/com.google.apis/google-api-services-drive
implementation('com.google.apis:google-api-services-drive:v3-rev136-1.25.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
implementation 'commons-codec:commons-codec:1.15'
How can I solve it?
Edit: these are the only apaches' libraries that I used in the whole project, but they have been used to write the .xlsx file in local and never gave me any kind of problem on the Galaxt Tab A before implementing the service credentials:
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

This is a known issue with the version of google-api-client-android you're using. The solution is to upgrade the version from 1.26 to 1.28 (or downgrade it to 1.25, see this comment).
I was able to reproduce the issue using an Empty Activity project and a virtual device with an API Level 26 and a Target Android 8.0 (Google APIs)
Build.gradle content :
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
//changing the version here from 1.26.0 to 1.28.0 resolves the issue
implementation('com.google.api-client:google-api-client-android:1.26.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
implementation('com.google.apis:google-api-services-drive:v3-rev136-1.25.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
implementation 'commons-codec:commons-codec:1.15'
}
MainActivity.java content:
package com.example.myapplication;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.services.drive.DriveScopes;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
authorize();
} catch (Exception e) {
e.printStackTrace();
}
}
private Credential authorize () throws IOException {
InputStream in = getAssets().open("credentials.json");
return GoogleCredential.fromStream(in)
.createScoped(Collections.singleton(DriveScopes.DRIVE_FILE));
}
}

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 resolve symbol com.googlecode.javacv.cpp.opencv_contrib.FaceRecognizer in android studio

So I have a project to create an face recognition app. In this project I tried to import :
import com.googlecode.javacv.cpp.opencv_contrib.FaceRecognizer;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_core.MatVector;
import com.googlecode.javacv.cpp.opencv_imgproc;
But gradle cannot find the symbol for it. I already import the java module from OpenCV library, but still cannot resolve it. Please help me.Thx
Here is the code for gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "example.com.facerecognation"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
}
dependencies {
implementation project(':openCVLibrary2410')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.github.bumptech.glide:glide:4.3.1'
implementation 'com.github.markushi:circlebutton:1.1'
implementation "androidx.cardview:cardview:1.0.0"
}
import static is for Methods.
Methods need to be in a class and classes need to be inside a package.
For example, you could have the class MyClass in the package com.example.
You can import this class using import com.example.MyClass.
If you want to statically import a method(e.g. myMethod) from this class, you'll need to write import static com.example.MyClass.myMethod
If you can do
import com.googlecode.javacv.cpp.opencv_core.MatVector;
that means that com.googlecode.javacv.cpp.opencv_core is a package.
Methods/constants need to be in a class.
Therefore, com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U cannot be imported statically.

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

Dagger build error

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})

getSupportFragmentManager().getFragments() shows a compile time error

Calling getSupportFragmentManager().getFragments() shows a compile time error with the message below:
getSupportFragmentManager().getFragments() can only be called from
within the same library group(groupId = com.android.support)
I have imported the following classes in MainActivity:
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
MainActivity extends AppCompatActivity.
My project module level build.gradle file is as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.mycompany.floatingdemo"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:support-vector-drawable:25.2.0'
testCompile 'junit:junit:4.12'
}
This is the source code for the method getFragments inside FragmentManager.java.
/**
* Get a list of all fragments that have been added to the fragment manager.
*
* #return The list of all fragments or null if none.
* #hide
*/
#RestrictTo(LIBRARY_GROUP)
public abstract List<Fragment> getFragments();
I have recently updated my Android Studio to the latest stable version (2.3) and updated the Android Gradle plugin as well. I think this may be relevant because I have not previously seen this error.
As noticeable in the FragmentManager documentation, getFragments() is not a public method available to apps, but an internal implementation detail of the Support Library, hence the use of the RestrictTo annotation that was added to prevent usage of private APIs.
You'll want to change your code to not use getFragments and only use the public APIs.
Alternative For those who may be using getFragments() in their coding, I have replaced my code to get last fragment in backstack to this code(I am using this code in onBackPressed() to apply changes according to currentFragment assumed all fragments are added to backstack):
FragmentManager.BackStackEntry backStackEntryAt = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1);
currentFragment = backStackEntryAt.getName();
You can use (make sure using 25.2.0 or higher )
supportFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentAttached(fm: FragmentManager?, f: Fragment?, context: Context?) {
f?.let { fList.add(it) }
}
override fun onFragmentDetached(fm: FragmentManager?, f: Fragment?) {
f?.let { fList.remove(it) }
}
}, false)
Instead of using getFragments()

Categories