Android – trying to add multidex support – unable to find symbol context and multidex

Follow the instructions mentioned below: https://developer.android.com/studio/build/multidex.html#mdex -gradle

I got an error. I can't find the symbol class context variable and the 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'
}

What do I have to add or import to make it work?

resolvent:

Thanks for @ Gabe sechan's help. I know react native / JavaScript and know nothing about Android / Java, so I just follow https://developer.android.com/studio/build/multidex.html#mdex -Description and operation of gradle, There was no mention of any additional imports. I learned to look at the packaging I needed: https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html. After adding:

import android.support.multidex.MultiDexApplication;

public class MainApplication extends MultiDexApplication implements ReactApplication {
...

The application seems to be built and run successfully on Android 4.4.4 devices. However, on the Samsung Galaxy S3 simulator running 4.3, I encountered a crash when the application was started: what does win death: Android. Osdeadobjectexception mean?, This seems to be another problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>