After following the instructions mentioned at: https://developer.android.com/studio/build/multidex.html#mdex-gradle
I am getting an error cannot find symbol
class Context
variable context
and variable MultiDex
.
package com.mycompany.mypackage;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.slowpath.hockeyapp.RNHockeyAppModule;
import com.slowpath.hockeyapp.RNHockeyAppPackage;
import com.microsoft.codepush.react.CodePush;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.sbugert.rnadmob.RNAdMobPackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
import com.geektime.reactnativeonesignal.ReactNativeOneSignalPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.reactnative.ivpusic.imagepicker.PickerPackage;
import com.github.xinthink.rnmk.ReactMaterialKitPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.burnweb.rnpermissions.RNPermissionsPackage;
import net.zubricky.AndroidKeyboardAdjust.AndroidKeyboardAdjustPackage;
// react-native-fbsdk
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
// react-native-fbads
import io.callstack.react.fbads.FBAdsPackage;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(context);
MultiDex.install(this);
}
// react-native-fbsdk
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
@Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
// If you want to use AppEventsLogger to log events.
AppEventsLogger.activateApp(this);
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNHockeyAppPackage(MainApplication.this),
new CodePush("mykey", MainApplication.this, BuildConfig.DEBUG),
new ReactNativeConfigPackage(),
new ReactNativeOneSignalPackage(),
new ReactNativePushNotificationPackage(),
new RNAdMobPackage(),
new PickerPackage(),
new ReactMaterialKitPackage(),
new RNDeviceInfo(),
new RNPermissionsPackage(),
new AndroidKeyboardAdjustPackage(),
new FBSDKPackage(mCallbackManager),
new FBAdsPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
build.gradle
dependencies {
compile project(':react-native-device-info')
compile project(':react-native-hockeyapp')
compile project(':react-native-code-push')
compile project(':react-native-image-crop-picker')
compile project(':react-native-vector-icons')
compile project(':react-native-material-kit')
compile project(':react-native-config')
compile project(':RNAdMob')
compile project(':react-native-onesignal')
compile project(':react-native-push-notification')
compile project(':RNPermissionsModule')
compile project(':react-native-android-keyboard-adjust')
compile project(':react-native-fbsdk')
compile(project(':react-native-fbads')) {
exclude group: "com.google.android.gms"
}
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-crash:10.2.0'
compile 'com.google.firebase:firebase-ads:10.2.0'
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.facebook.fresco:animated-gif:0.12.0"
compile 'com.android.support:multidex:1.0.1'
}
Is there something I have to add or import to get this to work?
Thanks to @Gabe Sechan for the help. I know React Native/JavaScript, kind of clueless about Android/Java, so I simply followed the instructions at https://developer.android.com/studio/build/multidex.html#mdex-gradle, which did not mention any additional imports. I learned to look up the package I needed here: https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html. After adding:
import android.support.multidex.MultiDexApplication;
public class MainApplication extends MultiDexApplication implements ReactApplication {
...
App seems to build and run successfully on Android 4.4.4+ devices. On my Samsung Galaxy S3 simulator running 4.3 however, I am getting a crash upon app start: What does WIN DEATH: android.osDeadObjectException mean?, which seems like another issue altogether.
The reason you are having this "symbol not found" issue is because you haven't imported the required imports. Why not simply add the following imports
import android.support.multidex.MultiDex;
import android.content.Context;
You should know the different cases for using each Multidex option. Kindly refer to https://developer.android.com/studio/build/multidex#java for all information relating to MultiDexing
来源:https://stackoverflow.com/questions/42614142/trying-to-add-multidex-support-cannot-find-symbol-context-and-multidex