简体   繁体   中英

Facebook Audience Network SDK not compiling

I am trying to use FAN in my app. I have followed the steps described in FAN help by Facebook https://developers.facebook.com/docs/audience-network/android/banner

and what I get is a compilation error, as the feeling that the res/layout.xml is incorrect.

I have done a clone of the git examples that are here GitHub FAN

I have to say that the documentation that I have found from Facebook is very poor, with examples not even compiling and lack of clear support.

In my AndroidManifest.xml I have

<!-- Declare Facebook app ID -->
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

    ...

    <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" />


    <provider android:authorities="com.facebook.app.FacebookContentProvider1759289410974589"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true" />

My /res/layout/main.xml contains the following:

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"

android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RelativeLayout
    android:id="@+id/adViewContainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    />

In my Java code I have this:

private AdView adView;  // Facebook ad

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    RelativeLayout adViewContainer = (RelativeLayout) findViewById(R.id.adViewContainer);

    adView = new AdView(this, getString(R.string.FacebookAudienceID), AdSize.BANNER_320_50);
    adViewContainer.addView(adView);
    adView.loadAd();

I am getting the following compilation error:

Error:(212, 44) error: incompatible types: String cannot be converted to AttributeSet Error:(214, 15) error: method loadAd in class BaseAdView cannot be applied to given types; required: AdRequest found: no arguments reason: actual and formal argument lists differ in length

I have googled to try to find out the root source of this error with no luck. Could you give me a hand with this issue? Thanks in advance.

I too got the same error. You probably should be using google ads or have google ads enabled in your project. Just delete the "AdView" next to the 'new' keyword and type the same again. In the dropdown list, choose AdView from facebook SDK. Something like this:

adView = new com.facebook.ads.AdView (this, getString(R.string.FacebookAudienceID), AdSize.BANNER_320_50);

The reason is that the 'AdView' uses the google SDK rather than the facebook SDK by default. Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM