按照https://developer.android.com/studio/build/multidex.html#mdex-gradle
中提到的说明操作后我收到错误class Context
variable context
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;
}
}
。
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'
}
的build.gradle
{{1}}
我是否需要添加或导入才能使其正常工作?
答案 0 :(得分:19)
感谢@Gabe Sechan的帮助。我知道React Native / JavaScript,对Android / Java很无能为力,所以我只是按照https://developer.android.com/studio/build/multidex.html#mdex-gradle的说明进行操作,但没有提及任何额外的导入。我学会了查看我需要的包裹:https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html。添加后:
import android.support.multidex.MultiDexApplication;
public class MainApplication extends MultiDexApplication implements ReactApplication {
...
应用似乎在Android 4.4.4+设备上构建并成功运行。然而,在运行4.3的三星Galaxy S3模拟器上,我在应用程序启动时遇到了崩溃:What does WIN DEATH: android.osDeadObjectException mean?,这似乎是另一个问题。
答案 1 :(得分:4)
如果您使用的是RN> 0.60和androidx支持,则可以添加,
import androidx.multidex.MultiDex;
答案 2 :(得分:1)
出现此“未找到符号”问题的原因是因为您没有导入所需的导入。 为什么不简单地添加以下导入
import android.support.multidex.MultiDex;
import android.content.Context;
您应该知道使用每个Multidex选项的不同情况。 请参阅https://developer.android.com/studio/build/multidex#java,以获取与MultiDexing相关的所有信息
答案 3 :(得分:1)
对于那些得到找不到符号错误的人,在android官方开发者文档中说明如下:
<块引用>If your minSdkVersion is 21 or higher multidex is enabled by default, and you do not need the multidex support library.
答案 4 :(得分:0)
将 dependencies: { implementation 'com.android.support:multidex:1.0.3' }
添加到 android/app/build.gradle 解决了我的问题。当我将 minSDKversion 提高到 21 时发生了这种情况。