[英]How to specify admob library in build.gradle?
Can I specify the AdMob library in the build.gradle in Android Studio to avoid having the AdMob jar locally? 我可以在Android Studio的build.gradle中指定AdMob库,以避免在本地使用AdMob jar吗?
I've tried 我试过了
dependencies {
compile 'com.google.ads:6.2.1+'
}
but it doesn't work. 但它不起作用。 Am I missing something?
我错过了什么吗?
Better if you use following: 如果您使用以下更好:
compile 'com.google.android.gms:play-services-ads:7.5.0'
Because, it will reduce your apk file size. 因为,它会减少你的apk文件大小。
The latest version of Google Mobile Ads SDK for Android was released as part of Google Play services 4.0 (See Release Notes on Blog ) 适用于Android的最新版Google移动广告SDK已作为Google Play服务4.0的一部分发布(请参阅博客上的发行说明 )
NOTE the following limitation: 请注意以下限制:
The Google Mobile Ads APIs in Google Play services currently does not support DoubleClick For Publishers (DFP), Ad Exchange, or Search Ads for Mobile Apps.
Google Play服务中的Google移动广告API目前不支持DFP广告管理系统,广告交易平台或移动应用搜索广告。
So all you need in your gradle dependencies for Google AdMob: 因此,Google AdMob的gradle依赖项中您只需要:
dependencies {
// ... Other entries
compile 'com.google.android.gms:play-services:4.0.30'
}
The rest of the setup is explained here: 其余的设置在这里解释:
https://developers.google.com/mobile-ads-sdk/docs/ https://developers.google.com/mobile-ads-sdk/docs/
With my project it didn't work to load ads directly after adding the support as described on the docs. 使用我的项目,在添加文档中所述的支持后,无法直接加载广告。 Instead it crashed initializing the layout.
相反,它崩溃了初始化布局。
What helped was one of the following things: 有什么帮助是以下之一:
I dont think the google admob files are available on maven central. 我不认为google admob文件可以在maven central上找到。 I think the only thing you can do is reference them locally
我认为你唯一能做的就是在本地引用它们
You need to include in you root build.gradle 您需要在root build.gradle中包含
allprojects {
repositories {
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
Then in your app/build.gradle you include 然后在你的app / build.gradle中包含
compile 'com.google.firebase:firebase-core:11.8.0'
in your dependencies block. 在你的依赖块中。 You must also this line at the bottom of your app/build.gradle
您还必须在app / build.gradle底部的这一行
apply plugin: 'com.google.gms.google-services'
在新版Android Studio中,它是这样的:
implementation 'com.google.android.gms:play-services-ads:11.8.0'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.