反应本机和fbsdk版本:
"react": "16.6.3",
"react-native": "0.58.5",
"react-native-fbsdk": "^0.8.0"
我遇到以下错误:
> Task :app:compileDebugJavaWithJavac FAILED
C:\Users\xxxx\Desktop\project\android\app\src\main\java\com\project\MainApplication.java:22: error: cannot find symbol
private static CallBackManager mCallbackManager = CallbackManager.Factory.create();
^
symbol: class CallBackManager
location: class MainApplication
C:\Users\xxxx\Desktop\project\android\app\src\main\java\com\project\MainApplication.java:24: error: cannot find symbol
protected static CallBackManager getCallbackManager() {
^
symbol: class CallBackManager
location: class MainApplication
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
该问题似乎与代码的这一部分有关,但我不太清楚出什么问题。我完全按照他们的official repository中提供的说明进行操作。
public class MainApplication extends Application implements ReactApplication {
private static CallBackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallBackManager getCallbackManager() {
return mCallbackManager;
}
// ...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new FBSDKPackage(mCallbackManager)
);
}
// ...
}
我还手动将以下导入添加到MainActivity.java
:
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
将这些行添加到app/build.gradle
:
implementation project(':react-native-fbsdk')
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
,然后将其发送到settings.gradle
:
include ':react-native-fbsdk'
project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android')
答案 0 :(得分:0)
如果有人偶然发现同一问题,则与npm无法将fb-sdk正确链接到项目有关。我尝试使用npm install
和npm link
,但是尽管npm没有抛出任何错误,但还是没有成功。但是,使用react-native
安装sdk可以解决此问题:
react-native install react-native-fbsdk
react-native link react-native-fbsdk
如果尝试链接时遇到MODULE_NOT_FOUND错误,请打开项目根文件夹上的命令行并运行:
cd android
gradlew clean
另外,尽管他们的官方GitHub repository确实包含有关安装过程的说明,但我建议您遵循facebook developers page,因为这样做在可读性和细节方面要好得多。