Cannot use FakeHttpLayer of Robolectric (NullPointerException when calling getFakeHttpLayer) - java

Update 1
After removing the ServiceTestCase extend of my test class, I edited my gradle file to change the testInstrumentationRunner to org.robolectric.RobolectricTestRunner but I get another error :
Running tests
Test running started
Test running failed: Instrumentation run failed due to 'java.lang.NoSuchMethodException'
Empty test suite.
I searched Google but I could not find out why I get this error message. Here is the whole gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "foo.bar.testappsdk"
minSdkVersion 9
targetSdkVersion 19
testApplicationId "novom.anyware.anywaresdk.test"
testInstrumentationRunner "org.robolectric.RobolectricTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'LICENSE.txt'
}
sourceSets {
instrumentTest.setRoot('src/androidTest')
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'novom.anyware.anywaresdk:anywaresdk#aar'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
androidTestCompile 'org.robolectric:robolectric:2.4'
androidTestCompile 'junit:junit:4.12'
}
End of update 1
I am trying to use Robolectric 2.4 to test the network calls of my Android Library. The problem is that I can't even get access to the FakeHttpLayer of Robolectric without getting a NullPointerException.
java.lang.NullPointerException: Attempt to invoke virtual method 'org.robolectric.tester.org.apache.http.FakeHttpLayer org.robolectric.shadows.ShadowApplication.getFakeHttpLayer()' on a null object reference
at org.robolectric.Robolectric.getFakeHttpLayer(Robolectric.java:1239)
at novom.anyware.anywaresdk.test.AWRSyncServiceTest.test_3_get_config(AWRSyncServiceTest.java:61)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1837)
There is my Test class :
#RunWith(RobolectricTestRunner.class)
public class AWRSyncServiceTest extends ServiceTestCase<AWRSyncService> {
private static final String TAG = "AWRSyncServiceTest";
private AWRSyncService syncService;
public AWRSyncServiceTest() {
super(AWRSyncService.class);
}
#Override
protected void setUp() throws Exception {
Log.d(TAG, "setUp");
super.setUp();
IBinder service = bindService(new Intent(getContext(), AWRSyncService.class));
AWRSyncService.SyncServiceBinder binder = (AWRSyncService.SyncServiceBinder) service;
syncService = binder.getService();
}
#Override
protected void tearDown() throws Exception {
Log.d(TAG, "tearDown");
super.tearDown();
}
public void test_1_preconditions() {
Log.d(TAG, "test_1_preconditions");
assertNotNull(syncService);
assertNotNull(syncService.getApplicationContext());
}
public void test_3_get_config() {
Robolectric.getFakeHttpLayer();
}
}
Am I missing some basic configuration that must be set to Robolectric before being able to use it? I can't find any good tutorial that would help me to understand what I did wrong.
Thank you

Not sure if this is why you have this specific problem, but one issue is that you are extending a ServiceTestCase. This is a problem, because you are now mixing Robolectric with Android Unit Tests.
Robolectric tests run on the JVM, not on device. Android Unit Tests ran on device.
You might also want to check this out in terms of how to test your service: http://robolectric.org/starting-components/

Probably it's because you are extending it from ServiceTestCase class. Don't use Android Unit Test suite for that. Also be sure you have created that class on JUnit 4.
Another thing is you should build the service with Robolectric way. Like this;
Robolectric.buildService(AWRSyncService.class).bind()
EDIT : Add these fields to your build.gradle file, these are from robolectric gradle plugin
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.robolectric:robolectric-gradle-plugin:0.13.2'
}
}
apply plugin: 'robolectric'
android {
sourceSets {
androidTest {
setRoot('src/androidTest')
}
}
robolectric {
include '**/*Test.class'
}

Related

Gradle Not Finding Method Implementation for Arguments

I am trying to build a simple maven library and I can't get it to build. I am using Gradle Groovy and Kotlin Multiplatform Library in IntelliJ IDEA.
I haven't even been able to begin coding since my dependencies wont load. I am very new to all this so bare with me.
This is my build.gradle
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.7.10'
}
group = 'me.me'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies{
implementation platform("io.cucumber:cucumber-bom:7.1.0")
implementation 'io.cucumber:cucumber-java'
implementation 'io.cucumber:cucumber-junit-platform-engine'
implementation 'io.cucumber:cucumber-junit'
implementation 'io.cucumber:cucumber-spring'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = '1.8'
}
withJava()
testRuns["test"].executionTask.configure {
useTestNG()
}
}
sourceSets {
commonMain {
}
commonTest {
dependencies {
implementation kotlin('test')
}
}
}
}
and this is the error I am getting
Build file '/Users/Me/Documents/GitHub/Project-Tools/build.gradle' line: 13
A problem occurred evaluating root project 'Project-Tools'.
> Could not find method implementation() for arguments
[DefaultExternalModuleDependency{group='io.cucumber', name='cucumber-bom', version='7.1.0', configuration='default'}]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I even tried commenting out each dependency one at a time so see if any work and none did
EDIT: Also I am on a Mac

Trying to implement cucumber.api.cli.Main.main()

I have tried to implement the 'cucumber.api.cli.Main' but I get the following error: "No backends were found. Please make sure you have a backend module on your CLASSPATH." Does this mean I am missing a dependency? My Gradle and java code is below.
java code
package cucumber;
import cucumber.api.cli.Main;
import java.io.PrintStream;
public class CucumberRunEngine {
public static void main(String[] args) {
try {
Main.main(
new String[]{
"CLASSPATH:src.main.groovy.cucumber.features.addDeal",
//"-t", "#Daily",
"-g", "cucumber.stepDefinitions",
"-p", "pretty",
"-p", "html:target/HTMLReports/report.html",
"-p", "junit:target/JUNITReports/report.xml",
"-p", "json:target/JSONReports/report.json",
"-m"
}
);
} catch (Exception e) {
PrintStream printer =System.out;
printer.println(e);
for (int element=0;element<e.getStackTrace().length;element++) {
printer.println(e.getStackTrace()[element]);
}
}
}
}
Gradle code
plugins {
id 'groovy'
id 'java-library'
id 'application'
id "se.thinkcode.cucumber-runner" version "0.0.8"
}
dependencies {
//Standard
api "org.codehaus.groovy:groovy-all:${groovyVersion}"
api "com.reuters:corejavalib:${coreJavaLibVersion}"
api "com.oracle:ojdbc7:${ojdbc7Version}"
implementation "commons-io:commons-io:${commonsIoVersion}"
implementation "commons-lang:commons-lang:${commonLangVersion}"
//JUnit
implementation "junit:junit:${jUnitVersion}"
// implementation("org.junit.platform:junit-platform-suite")
compileOnly "org.testng:testng:${testNGVersion}"
//Cucumber
compileOnly "io.cucumber:cucumber-java:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-java8:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-junit:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-groovy:${cucumberGroovyVersion}"
compileOnly "io.cucumber:cucumber-gherkin:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-jvm-groovy:${cucumberGroovyVersion}"
compileOnly "io.cucumber:cucumber-junit-platform-engine:${cucumberVersion}"
implementation "io.cucumber:cucumber-core:${cucumberVersion}"
}
application{
mainClass="cucumber.CucumberRunEngine"
}
repositories {
}
Gradle.properties
# versions of dependencies used in this project defined here
groovyVersion=2.5.7
commonCliVersion=1.3.1
commonsIoVersion=2.6
commonLangVersion=2.6
#JUnit
jUnitVersion=4.8
testNGVersion=7.4.0
jUnitPlatformSuiteVersion=1.9.0
#Cucumber
cucumberVersion=7.4.0
cucumberGroovyVersion=6.10.4
ojdbc7Version=12.1.0.2
coreJavaLibVersion=3.5.21.9
Thank you for any help in advance :)
Your project setup is a bit peculiar. There are too many parts that simply don't belong. For example as a result of using compileOnly you're not including the code you need at runtime. And so Cucumber complains it can't find cucumber-java (a backend).
Now you may have already noticed this and scoped cucumber-core to implementation for this reason. But this suggests you're fixing one error at a time rather then building a fundamental understanding of the tools you use.
So it's worth reading how Gradle does dependency management for you:
https://docs.gradle.org/5.3.1/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
A minimal example can be found in the skeleton project. It is not tailored to your needs, but it should be a good starting point.
https://github.com/cucumber/cucumber-java-skeleton
plugins {
java
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.0"))
testImplementation(platform("io.cucumber:cucumber-bom:7.6.0"))
testImplementation("io.cucumber:cucumber-java")
testImplementation("io.cucumber:cucumber-junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-suite")
testImplementation("org.junit.jupiter:junit-jupiter")
}
repositories {
mavenLocal()
mavenCentral()
}
tasks.withType<Test> {
useJUnitPlatform()
// Work around. Gradle does not include enough information to disambiguate
// between different examples and scenarios.
systemProperty("cucumber.junit-platform.naming-strategy", "long")
}

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

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.

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