2017-07-06 104 views
1

最近,我一直在嘗試將facebooksdk設置爲我的反應原生應用程序。我已經經歷了很多帖子,但是在安裝過程中我仍然遇到了很多錯誤。react-native-fbsdk錯誤:package com.facebook.reactnative.androidsdk does not exist

我跟着guide,我安裝使用NPM [email protected](因爲最新版本有錯誤),我跑了反應本地鏈路反應母語-fbsdk

下面是我的設置

MainApplicaiton.Java

package com.ddc; 

import android.app.Application; 

import com.facebook.react.ReactApplication; 
import com.facebook.reactnative.androidsdk.FBSDKPackage; 
import com.oblador.vectoricons.VectorIconsPackage; 
import com.facebook.react.ReactNativeHost; 
import com.facebook.react.ReactPackage; 
import com.facebook.react.shell.MainReactPackage; 
import com.facebook.soloader.SoLoader; 
import com.facebook.CallbackManager; 
import com.facebook.FacebookSdk; 

import java.util.Arrays; 
import java.util.List; 

public class MainApplication extends Application implements ReactApplication { 

    private static CallbackManager mCallbackManager = CallbackManager.Factory.create(); 

    protected static CallbackManager getCallbackManager() { 
    return mCallbackManager; 
    } 

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 
    @Override 
    public boolean getUseDeveloperSupport() { 
     return BuildConfig.DEBUG; 
    } 

    @Override 
    protected List<ReactPackage> getPackages() { 
     return Arrays.<ReactPackage>asList(
      new MainReactPackage(), 
      new FBSDKPackage(mCallbackManager), 
      new VectorIconsPackage() 
    ); 
    } 
    }; 

    @Override 
    public ReactNativeHost getReactNativeHost() { 
    return mReactNativeHost; 
    } 

    @Override 
    public void onCreate() { 
    super.onCreate(); 
    FacebookSdk.sdkInitialize(getApplicationContext()); 
    } 
} 

MainActivity.Java

package com.ddc; 

import com.facebook.react.ReactActivity; 
import android.content.Intent; 

public class MainActivity extends ReactActivity { 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data); 
    } 

    /** 
    * Returns the name of the main component registered from JavaScript. 
    * This is used to schedule rendering of the component. 
    */ 
    @Override 
    protected String getMainComponentName() { 
     return "DDC"; 
    } 
} 

我的build.gradle

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 

    defaultConfig { 
     applicationId "com.ddc" 
     minSdkVersion 16 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
     ndk { 
      abiFilters "armeabi-v7a", "x86" 
     } 
    } 
    splits { 
     abi { 
      reset() 
      enable enableSeparateBuildPerCPUArchitecture 
      universalApk false // If true, also generate a universal APK 
      include "armeabi-v7a", "x86" 
     } 
    } 
    buildTypes { 
     release { 
      minifyEnabled enableProguardInReleaseBuilds 
      proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 
     } 
    } 
    // applicationVariants are e.g. debug, release 
    applicationVariants.all { variant -> 
     variant.outputs.each { output -> 
      // For each separate APK per architecture, set a unique version code as described here: 
      // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 
      def versionCodes = ["armeabi-v7a":1, "x86":2] 
      def abi = output.getFilter(OutputFile.ABI) 
      if (abi != null) { // null for the universal-debug, universal-release variants 
       output.versionCodeOverride = 
         versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 
      } 
     } 
    } 
} 

dependencies { 
    compile project(':react-native-vector-icons') 
    compile fileTree(dir: "libs", include: ["*.jar"]) 
    compile "com.android.support:appcompat-v7:23.0.1" 
    compile "com.facebook.react:react-native:+" // From node_modules 
} 

這是結果我有

enter image description here

+0

我有同樣的問題,但我認爲它更多的是一個bug,希望有人知道修復並回答這個問題! –

+0

@ShariqMusharaf你是否介意分享,如果你找到解決方案? –

+1

@ShariqMusharaf在build.grade中加入:compile(project(':react-native-fbsdk')){ exclude(group:'com.facebook.android',module:'facebook-android-sdk') } compile「com.facebook.android:facebook-android-sdk:4.22.1」 –

回答

3

添加此行到您的gradle.build:

compile(project(':react-native-fbsdk')) { 
exclude(group: 'com.facebook.android', module: 'facebook-android-sdk') 
} 
compile('com.facebook.android:facebook-android-sdk:4.22.1') 
相關問題