I tried to integrated Facebook Android SDK(4.25.0) into my app. Everything worked fine if I used Gradle build in Android Studio.
It didn't work if I integrated with my AOSP(Android open source project) source code. There is no compile error. but when I call
FacebookSdk.sdkInitialize(this.getApplicationContext());
//if I didn't call this method, it gave me another exception said
'The SDK has not been initialized, make sure to call
FacebookSdk.sdkInitialize() first.'
I got below exception:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/R$style;
at com.facebook.FacebookSdk.<clinit>(FacebookSdk.java:84)
My mk file looks like:
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/design/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/cardview/res
LOCAL_STATIC_JAVA_AAR_LIBRARIES := facebook-android-sdk
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
facebook-android-sdk:libs/facebook-android-sdk-4.25.1.aar \
bolts-android:libs/bolts-android-1.4.0.jar
Any suggestion? Thanks in advance.
I also run into this error most of the times I add 3rd party libs to an AOSP app build. What usually works is the following:
1) "convert" your .aar to a .jar (extract it, rename the classes.jar to facebook-android-sdk-4.25.1.jar, copy the res folder somewhere you can link to.)
2) add the following to your .mk file:
LOCAL_STATIC_JAVA_LIBRARIES += facebook-android
...
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS := --extra-packages com.facebook
...
LOCAL_RESOURCE_DIR += /path/to/facebook-android-sdk-RES/
...
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += facebook-android:/path/to/the/facebook-android-sdk-4.25.1.jar
3) add all dependcies to the build (appcompat, gridlayout, customtabs, etc. the link to the facebook-sdk you posted shows them.)
I am not sure if you can skip the first step since it depends on your android version (Link to the commit). I am on older versions where LOCAL_STATIC_JAVA_AAR_LIBRARIES
does not exist(But you dont get an error if you still use it).
But your error message Failed resolution of: Lcom/facebook/R$style
indicates me that thats also the case for you.