react andation and fbsdk版本:
"react": "16.6.3",
"react-native": "0.58.5",
"react-native-fbsdk": "^0.8.0"
我有以下错误:
> Task :app:compileDebugJavaWithJavac FAILED
C:UsersxxxxDesktopprojectandroidappsrcmainjavacomprojectMainApplication.java:22: error: cannot find symbol
private static CallBackManager mCallbackManager = CallbackManager.Factory.create();
^
symbol: class CallBackManager
location: class MainApplication
C:UsersxxxxDesktopprojectandroidappsrcmainjavacomprojectMainApplication.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.
这个问题似乎与代码的这一部分有关,但我无法弄清楚什么问题。我完全遵循其正式存储库中提供的说明。
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')
如果某人碰巧遇到了同样的问题,这与NPM无链接FB-SDK有关。我尝试使用npm install
和npm link
,但尽管没有任何错误,但没有成功。但是,使用react-native
安装SDK解决了问题:
react-native install react-native-fbsdk
react-native link react-native-fbsdk
试图链接时是否遇到Module_NOT_FOUND错误,请在项目root文件夹上打开命令行并运行:
cd android
gradlew clean
此外,尽管他们的官方GitHub存储库确实包含有关安装过程的说明,但我建议使用Facebook开发人员页面,因为它在可读性和详细信息方面要好得多。