我正在尝试使用react native和fbsdk wrapper https://github.com/facebook/react-native-fbsdk在Android上设置fbsdk。我有它在iOS上工作,但我被困在Android上。我按照github自述文件执行了所有步骤。
MainApplication.java
@Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
SoLoader.init(this, /* native exopackage */ false);
}
的strings.xml
<resources>
<string name="app_name">FacebookLogin</string>
<string name="facebook_app_id">1343643482425305</string>
<string name="fb_login_protocol_scheme">fb1343643482425305</string>
</resources>
的AndroidManifest.xml
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
但是我从LogCat
收到此错误11-22 06:57:13.236 7570-7570/? I/zygote: Not late-enabling -Xcheck:jni (already on)
11-22 06:57:13.244 7570-7570/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
11-22 06:57:13.361 7570-7570/com.facebooklogin I/FacebookInitProvider: Failed to auto initialize the Facebook SDK
A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:276)
at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:232)
at com.facebook.internal.FacebookInitProvider.onCreate(FacebookInitProvider.java:20)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1919)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1894)
at android.app.ActivityThread.installProvider(ActivityThread.java:6285)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5851)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5772)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
11-22 06:57:13.364 7570-7570/com.facebooklogin D/AndroidRuntime: Shutting down VM
11-22 06:57:13.365 7570-7570/com.facebooklogin E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.facebooklogin, PID: 7570
java.lang.RuntimeException: Unable to create application com.facebooklogin.MainApplication: A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5794)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:276)
at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:232)
at com.facebooklogin.MainApplication.onCreate(MainApplication.java:53)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
答案 0 :(得分:1)
在我的情况下,元数据位于应用程序范围之外。通常,它应位于清单中,如下所示:
<application>
...
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
</application>
答案 1 :(得分:0)
在build.gradle(Module:app)文件中添加以下内容:
repositories {
mavenCentral()
}
和
compile 'com.facebook.android:facebook-android-sdk:4.10.0'
现在在AndroidManifest.xml文件中添加以下内容:
<activity android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
在activity_main.xml文件中添加以下内容:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.demonuts.fblogin.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/text"/>
<com.facebook.login.widget.LoginButton
android:id="@+id/btnfb"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
答案 2 :(得分:0)
尝试替换:
const CityPicker = ({ handleCityChange }) => {
const [allCities, setAllCities] = useState([]);
const [states, setStates] = useState([]);
const [counties, setCounties] = useState(null);
useEffect(() => {
const fetchAPI = async () => {
const cities = await fetchCity();
setAllCities(cities);
setStates([...new Set(cities.map(city => city.province))]);
};
fetchAPI();
}, []);
function handleSelectState = function(state) {
setCounties([
...new Set(allCities
.filter(city => city.province === state)
.map(city => city.county)
)
]);
};
return (
<FormControl className={styles.formControl}>
<NativeSelect
defaultValue=" "
onChange={e => handleSelectState(e.target.value)}
>
<option value="">States</option>
{states.map((state, i) => (
<option key={i} value={state}>
{state}
</option>
))}
</NativeSelect>
{ counties &&
<NativeSelect defaultValue=" ">
<option value="">States</option>
{counties.map((county, i) => (
<option key={i} value={county}>
{county}
</option>
))}
</NativeSelect>
}
</FormControl>
);
};
export default CityPicker;
与
private Slider createStarRankSlider(int id) {
Slider starRank = new Slider();
starRank.setEditable(true);
starRank.setMinValue(0);
starRank.setMaxValue(10);
int fontSize = Display.getInstance().convertToPixels(3);
Font fnt = Font.createTrueTypeFont("Handlee", "Handlee-Regular.ttf").
derive(fontSize, Font.STYLE_PLAIN);
Style s = new Style(0xffff33, 0, fnt, (byte) 0);
Image fullStar = FontImage.createMaterial(FontImage.MATERIAL_STAR, s).toImage();
s.setOpacity(100);
s.setFgColor(0);
Image emptyStar = FontImage.createMaterial(FontImage.MATERIAL_STAR, s).toImage();
initStarRankStyle(starRank.getSliderEmptySelectedStyle(), emptyStar);
initStarRankStyle(starRank.getSliderEmptyUnselectedStyle(), emptyStar);
initStarRankStyle(starRank.getSliderFullSelectedStyle(), fullStar);
initStarRankStyle(starRank.getSliderFullUnselectedStyle(), fullStar);
starRank.setPreferredSize(new Dimension(fullStar.getWidth() * 5, fullStar.getHeight()));
starRank.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
ServiceTask.getInstance().UpdateRank(id,starRank.getIncrements());
Dialog.show("Success","thank you for rating our product",new Command("OK"));
}
});
return starRank;
}