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

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

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

No static method decodeBase64 - Google Credential

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

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

How do I enable multidex for react native?

I'm pretty sure its a built in feature but I cant find anything when searching or in the docs. Is there a flag for building with multidex enabled?
On another note:
Any way to see which libraries are messing with your method count? Hitting the 64k limit came as quite a surprise.
For RN 0.59+ and using Gradle 3.4.1, none of the answers here had the complete solution. I did the following and it worked:
In android/app/build.gradle, update the dependency block:
dependencies {
// ... your other dependencies
// Multidex
implementation 'com.android.support:multidex:1.0.3'
}
And also update the defaultConfig in the android block:
defaultConfig {
// ... your `applicationId`, etc.
multiDexEnabled true
}
In MainApplication.java, replace
import android.app.Application;
at the top with
import android.support.multidex.MultiDexApplication;
OR if you're on RN 0.60+ or have manually upgraded to AndroidX then use this instead:
import androidx.multidex.MultiDexApplication;
Still in MainApplication.java, replace
public class MainApplication extends Application implements ReactApplication {
with
public class MainApplication extends MultiDexApplication implements ReactApplication {
Found the answer somewhere else. It's no different than enabling it for any regular Android project.
android {
....
defaultConfig {
...
multiDexEnabled true
}
As for method count, this site does the trick: http://inloop.github.io/apk-method-count/
android/app/build.gradle
android {
....
defaultConfig {
...
multiDexEnabled true
}
If you are using Multidex, your Application should extends MultiDexApplication instead of Application.
MyApplication.java
import android.support.multidex.MultiDexApplication;
public class MyApplication extends MultiDexApplication{
...
}
Since Application must extend ReactApplication, I used a similar approach to the one suggested here which is documented in point 2 in the Android Developer reference on multidex to attach to the base context:
app/build.gradle
android {
compileSdkVersion projectCompileSdkVersion // Or your version
defaultConfig {
minSdkVersion projectMinSdkVersion // Or your version
targetSdkVersion projectTargetSdkVersion // Or your version
multiDexEnabled true // *
}
dexOptions {
jumboMode true // *
}
}
dependencies {
compile 'com.android.support:multidex:1.0.3' // https://mvnrepository.com/artifact/com.android.support/multidex
}
MainApplication.java
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
https://developer.android.com/studio/build/multidex
Step:1
Open the /android/app/build.gradle
android {
...
defaultConfig {
...
multiDexEnabled true <-- ADD THIS LINE
}
}
Step:2
In the same file find dependencies
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1' <-- ADD THIS LINE
...
}
Note: To know latest version for multidex Multidex Latest Version
Step:3
Open the MainApplication.java file under
android/app/src/main/java/.../MainApplication.java
Add the multidex Import
// ... all your other imports here
import androidx.multidex.MultiDexApplication; <-- ADD THIS LINE
Our class definition needs extends MultiDexApplication like below
Beofre (In my case)
public class MainApplication extends Application implements ReactApplication {
After
public class MainApplication extends MultiDexApplication implements ReactApplication {
Replace Application with MultiDexApplication
Spet:4 (Optional)
clean the project
Reference How To Enable Multidex in Android
Hope this helps ;)

Categories