No static method getDefaultAPIVersion when calling FacebookSdk.sdkInitialize

1

I have migrated a project I had done 2 years ago from Eclipse to Android Studio, and in doing so I realized that Facebook classes no longer work the same. After also migrating the classes to the Facebook v4.0 API and getting the Android Studio to not give me any compilation problems, I launch the app on my mobile and it gives me this error:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.dreamseek.flyingninjapig, PID: 14375
                  java.lang.NoSuchMethodError: No static method getDefaultAPIVersion()Ljava/lang/String; in class Lcom/facebook/internal/ServerProtocol; or its super classes (declaration of 'com.facebook.internal.ServerProtocol' appears in /data/data/com.dreamseek.flyingninjapig/files/instant-run/dex/slice-slice_0-classes.dex)
                      at com.facebook.FacebookSdk.<clinit>(FacebookSdk.java:85)
                      at com.dreamseek.flyingninjapig.Main.onCreate(Main.java:80)
                      at android.app.Activity.performCreate(Activity.java:6272)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
                      at android.app.ActivityThread.access$900(ActivityThread.java:157)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5551)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

My onCreate method does the following:

protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    vista = new GameView(this);
    setContentView(vista);

    super.onCreate(savedInstanceState);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // gesti�n del Locale
    Configuration config = getBaseContext().getResources()
            .getConfiguration();

    // 1) Compruebo si en SharedPreferences hay elegido un idioma
    SharedPreferences prefs;
    prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);
    lang = prefs.getString("selectedLanguage", "");

    // 2) Si no, tomo el defaultLocale de la APP
    if (lang.equals(""))
        lang = getString(R.string.defaultLocale);

    if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) {
        locale = new Locale(lang);
        Locale.setDefault(locale);
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());
    }


    // Initialize the SDK before executing any other operations,
    FacebookSdk.sdkInitialize(getApplicationContext());
}

Do you know why it can be? I made the substitutions of the manifest that were said in the migration guide of facebook developers and I do not know what else it can be. I leave you also my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.0'
    compileOptions.encoding = 'iso-8859-1'

    defaultConfig {
        applicationId "com.dreamseek.flyingninjapig"
        minSdkVersion 15
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile project(':baseGameUtils')
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.facebook.android:facebook-android-sdk:4.+'
}

Thanks

    
asked by José Antonio Romero Piernas 26.10.2016 в 14:14
source

1 answer

2

Solved !!! When I brought the project from ADT, I incorporated a facebook library as MODULE. Although I removed it from the modules, something must have remained in the data generated by Android Studio. I have done a clean project and a rebuild and now it goes with pearls. Greetings!

    
answered by 27.10.2016 в 09:42