Twitter 获取资源编号 0x00000000 的值时没有包标识符

Twitter No package identifier when getting value for resource number 0x00000000

我正在尝试在我的 android 应用程序中实现 Twitter 登录。 我已经按照说明 ( https://dev.twitter.com/twitter-kit/android/twitter-login ) 但是当我调用 Fabric.with(this, new Twitter(authConfig));发生以下异常。

06-02 14:03:00.267    5623-5638/it.quepasa W/ResourceType﹕ No package identifier when getting value for resource number 0x00000000
06-02 14:03:00.323    5623-5638/it.quepasa E/Fabric﹕ Could not calculate hash for app icon.
android.content.res.Resources$NotFoundException: Resource ID #0x0
        at android.content.res.Resources.getValue(Resources.java:1033)
        at android.content.res.Resources.openRawResource(Resources.java:958)
        at android.content.res.Resources.openRawResource(Resources.java:940)
        at io.fabric.sdk.android.services.common.CommonUtils.getAppIconHashOrNull(CommonUtils.java:861)
        at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:97)
        at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
        at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
        at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
        at io.fabric.sdk.android.services.concurrency.AsyncTask.call(AsyncTask.java:311)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:838)
06-02 14:03:00.331    5623-5638/it.quepasa W/ResourceType﹕ No package identifier when getting value for resource number 0x00000000
06-02 14:03:00.333    5623-5638/it.quepasa E/Fabric﹕ Could not calculate hash for app icon.
android.content.res.Resources$NotFoundException: Resource ID #0x0
        at android.content.res.Resources.getValue(Resources.java:1033)
        at android.content.res.Resources.openRawResource(Resources.java:958)
        at android.content.res.Resources.openRawResource(Resources.java:940)
        at  io.fabric.sdk.android.services.common.CommonUtils.getAppIconHashOrNull(CommonUtils.java:861)
        at io.fabric.sdk.android.services.settings.Settings.initialize(Settings.java:90)
        at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:123)
        at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:99)
        at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
        at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
        at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
        at io.fabric.sdk.android.services.concurrency.AsyncTask.call(AsyncTask.java:311)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:838)

我尝试使用 fabric 插件为 android studio 重做所有过程,但它只是重做了我手动执行的步骤,问题仍然存在。

当我点击登录按钮时出现另一个异常:

06-02 11:22:23.611  24124-24124/it.quepasa E/Twitter﹕ Failed to get request token
com.twitter.sdk.android.core.TwitterApiException: method POST must have a request body.
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
        at retrofit.RestAdapter$RestHandler.access0(RestAdapter.java:220)
        at retrofit.RestAdapter$RestHandler.obtainResponse(RestAdapter.java:278)
        at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at retrofit.Platform$Android.run(Platform.java:142)
        at java.lang.Thread.run(Thread.java:838)
06-02 11:22:23.686  24124-24124/it.quepasa E/Twitter﹕ Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
        at com.twitter.sdk.android.core.identity.OAuthController.failure(OAuthController.java:78)
        at com.twitter.sdk.android.core.internal.oauth.OAuth1aService.failure(OAuth1aService.java:198)
        at com.twitter.sdk.android.core.Callback.failure(Callback.java:28)
        at retrofit.CallbackRunnable.run(CallbackRunnable.java:53)
        at android.os.Handler.handleCallback(Handler.java:800)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:194)
        at android.app.ActivityThread.main(ActivityThread.java:5370)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
        at dalvik.system.NativeStart.main(Native Method)

这是我的代码:

AndroidManifest.xml:

    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="XXXXXXXX" />

MainActivity.java:

    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig), new Crashlytics()); //I've tried without crashlytics, same problem. Crashlytics works..

LoginActivity.java:

    loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_buttons);
    loginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "Success");
        }

        @Override
        public void failure(TwitterException exception) {
            Log.d(TAG, "Failure");
        }
    });

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    loginButton.onActivityResult(requestCode, resultCode, data);
}

有什么想法吗?我在这上面浪费了太多时间:(

谢谢!

注意:我没有安装 Twitter 应用程序。它应该在网络视图中工作。

找到第一个异常的问题。显然有两个不同的问题。

在我的 AndroidManifest.xml 中,我在 <application ...>

中缺少属性 android:icon

希望这对其他人有所帮助。