无法使用 Facebook Android SDK 和 Facebook Audience Network SDK 编译
Posted
技术标签:
【中文标题】无法使用 Facebook Android SDK 和 Facebook Audience Network SDK 编译【英文标题】:Can't compile with Facebook Android SDK and Facebook Audience Network SDK 【发布时间】:2017-11-27 07:51:36 【问题描述】:我有一个 react-native 应用,我正在尝试使用中介适配器导入 FB android SDK 和 FB Audience Network SDK。
当我在我的 app/build.gradle 中添加这些依赖项时,我在构建期间收到以下错误。
compile 'com.facebook.android:facebook-android-sdk:4.22.1'
compile 'com.facebook.android:audience-network-sdk:4.26.1'
compile 'com.google.ads.mediation:facebook:4.26.1.0'
错误:
C:\ig3\android\app\build\intermediates\res\merged\debug\values-v24\values-v24.xml:3: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
C:\ig3\android\app\build\intermediates\res\merged\debug\values-v24\values-v24.xml:4: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
C:\ig3\android\app\build\intermediates\res\merged\debug\values-v24\values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
C:\ig3\android\app\build\intermediates\res\merged\debug\values-v24\values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
我可以编译我的项目的唯一方法是在 android/build.gradle 中执行此操作:
allprojects
....
configurations.all
resolutionStrategy
eachDependency DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native')
details.useVersion "0.49.5" // Your real React Native version here
force 'com.facebook.android:facebook-android-sdk:4.22.1' <---Add this line
force 'com.facebook.android:audience-network-sdk:4.26.1' <---Add this line
并在android/app/build.gradle中注释掉这两行:
//compile 'com.facebook.android:facebook-android-sdk:4.22.1'
//compile 'com.facebook.android:audience-network-sdk:4.26.1'
compile 'com.google.ads.mediation:facebook:4.26.1.0'
如果我在 android/build.gradle 中尝试任何其他版本的 FB Android SDK,我会遇到前面提到的相同错误。经过一番研究,我尝试更改 com.android.support:appcompat 版本,但如果我不使用 23,它总是会出现与上述相同的错误。
这是包含这些依赖项的可接受方式吗?感觉就像是 hack,我不知道为什么我不能只将 sdk 包含在 android/app/build.gradle 中,而且我不想永远卡在 FB android sdk 版本 4.22.1 上。
另外,经过测试,Admob 似乎无法为 Facebook Audience Network 提供广告中介功能,但我不确定这是否是由于我导入上述 sdk 的方式或不相关的问题。
如果有人能告诉我如何正确包含 sdks,我将不胜感激。谢谢!
编辑: 完整的android/build.gradle
buildscript
repositories
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
mavenLocal()
jcenter()
mavenCentral()
maven url "https://jitpack.io"
maven url 'https://maven.google.com'
maven
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
configurations.all
resolutionStrategy
eachDependency DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native')
details.useVersion "0.49.5" // Your real React Native version here
force 'com.facebook.android:facebook-android-sdk:4.22.1'
force 'com.facebook.android:audience-network-sdk:4.26.1'
还有完整的 android/app/build.gradle:
android
compileSdkVersion 23
buildToolsVersion '25.0.2'
defaultConfig
applicationId "com.myapp"
minSdkVersion 16
targetSdkVersion 22
versionCode 50
versionName "1.11.11"
ndk
abiFilters "armeabi-v7a", "x86"
multiDexEnabled true
dexOptions
jumboMode = true
javaMaxHeapSize "4g"
signingConfigs
release
....
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"
signingConfig signingConfigs.release
// 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
repositories
mavenCentral()
dependencies
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.android.support:appcompat-v7:23+'
compile project(':react-native-fetch-blob')
compile 'com.android.support:multidex:1.0.1'
compile project(':react-native-billing')
compile project(':bugsnag-react-native')
compile project(':react-native-admob')
compile fileTree(dir: "libs", include: ["*.jar"])
compile project(':react-native-fbsdk')
compile project(':react-native-code-push')
compile project(':react-native-device-info')
compile project(':react-native-config')
compile project(':react-native-fast-image')
compile project(':react-native-camera')
compile project(':react-native-google-analytics-bridge')
compile project(':react-native-vector-icons')
compile(project(":react-native-google-signin"))
exclude group: "com.google.android.gms" // very important
compile 'com.google.android.gms:play-services-auth:11.6.0'
compile 'com.google.firebase:firebase-appindexing:11.6.0'
compile 'com.facebook.android:facebook-android-sdk:4.22.1'
compile 'com.facebook.android:audience-network-sdk:4.26.1'
compile 'com.google.ads.mediation:facebook:4.26.1.0'
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy)
from configurations.compile
into 'libs'
【问题讨论】:
我知道这可能根本不是您想要的,但我今天在使用compile 'com.google.android.gms:play-services-auth:11.6.0'
和 compile 'com.facebook.android:facebook-android-sdk:4.22.1'
时遇到了问题,请检查删除 play-services-auth 是否有任何作用。
@H.***s 删除 play-services-auth 没有任何效果。如果我删除compile 'com.facebook.android:audience-network-sdk:4.26.1'
,那么我的应用程序就会构建(来自上面的完整 android/app/build.gradle)。然而,这是我需要的东西。有什么想法吗?
让我检查一下,然后我会回复你。
【参考方案1】:
我的解决方案是更新所有这些:
gradle to 3.01
gradle wrapper to 4.1
compilesdkversion to 26
buildtoolsversion to 26.02
com.android.support:appcompat-v7 to 26+
com.facebook.android:facebook-android-sdk:4.28.0
我的应用构建成功
【讨论】:
以上是关于无法使用 Facebook Android SDK 和 Facebook Audience Network SDK 编译的主要内容,如果未能解决你的问题,请参考以下文章
无法登录 / Facebook Unity SDK & Android
统一添加facebook sdk后无法合并android清单
无法在 Android 上编写 jarlist 缓存文件 Facebook SDK
Android:在eclipse中导入facebook sdk 4.10.1