我有一个React-Native
项目。这个项目从Expo
开始,然后被弹出切换到react-native
。expo
库仍在使用中,因此我被迫更新expo
并从react-native-unimodules
迁移到expo模块。
我已经使用了下面链接中的所有参考资料。
我已经成功地让它在IOS上工作,但是在android上,我仍然被以下错误困住了几个小时
错误:包expo.modules不存在 ...import expo.modules.ApplicationLifecycleDispatcher;
我认为expo.modules库没有在android上初始化,即使我已经配置了博览文档中提到的所有步骤
有人能知道问题出在哪里吗?
下面是正在出现的错误列表上的屏幕快照
&以下是mainApplication.java:
package com.myapp.app;
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import androidx.annotation.NonNull;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.reactcommunity.rndatetimepicker.RNDateTimePickerPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
//import com.teamvate.app.generated.BasePackageList;
//import org.unimodules.adapters.react.ModuleRegistryAdapter;
// import org.unimodules.adapters.react.ReactModuleRegistryProvider;
// import org.unimodules.core.interfaces.Package;
// import org.unimodules.core.interfaces.SingletonModule;
//import expo.modules.updates.UpdatesController;
import expo.modules.ApplicationLifecycleDispatcher;
import expo.modules.ReactNativeHostWrapper;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
// import javax.annotation.Nullable;
public class MainApplication extends Application implements ReactApplication {
// private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(
// new BasePackageList().getPackageList()
// );
private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(this, new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
// Packages that cannot be autolinked yet can be added manually here, for example:
packages.add(new ApplicationLifecycleDispatcher());
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
// @Override
// protected @Nullable String getJSBundleFile() {
// if (BuildConfig.DEBUG) {
// return super.getJSBundleFile();
// } else {
// return UpdatesController.getInstance().getLaunchAssetFile();
// }
// }
// @Override
// protected @Nullable String getBundleAssetName() {
// if (BuildConfig.DEBUG) {
// return super.getBundleAssetName();
// } else {
// return UpdatesController.getInstance().getBundleAssetName();
// }
// }
});
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
// if (!BuildConfig.DEBUG) {
// UpdatesController.initialize(this);
// }
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
ApplicationLifecycleDispatcher.onApplicationCreate(this);
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig);
}
/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(
Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.myapp.app.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
发布于 2022-03-04 01:03:08
Java类文件ApplicationLifecycleDispatcher
和ReactNativeHostWrapper
都存在于npm模块expo
中,这是expo的主要包。这个包裹可能有问题。
验证package.json中的依赖项为
"expo": ">=44.0.0-0 <45.0.0",
您可以运行yarn --check-files
以确保文件是正确的。
另外,
确保您使用最新的世博会CLI;Expo @5.0.2或更高版本是必需的。
npm i -g expo-cli
确保您使用的是最新的世博会EAS CLI;
npm i -g eas-cli
验证运行expo upgrade
时没有错误。
https://stackoverflow.com/questions/71284406
复制相似问题