通过实现Android的工作室和“新建”谷歌Play服务SDK谷歌广告工作室、广告、Android、谷歌

2023-09-07 01:34:20 作者:为你拒绝所有暧昧i

使用Android的工作室编译谷歌广告通过谷歌Play服务SDK。当我将此标记添加到Android清单文件:

Using Android Studio to compile Google Ads via Google Play Services SDK. When I add this tag to my Android manifest file:

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

我得到了'GOOGLE_PLAY_SERVICES_VERSION'整数值是没有定义一个编译器错误 - 这些引号中的文本也错误红色。有什么问题?

I get a compiler error that the integer value for 'google_play_services_version' is not defined - the text inside these quotes is also error red. What is the problem?

推荐答案

您会发现许多'提示'和'窍门'来获得使用新的谷歌Play服务库运行Android的广告。其中的大多数将有你追你的尾巴添加jar文件到库文件夹,并增加这些jar文件里面找到您的项目设置/结构界面中的库引用。事实上,谷歌将广告通过Android Studio中的Andr​​oid项目要求:

You will find many 'tips' and 'tricks' to get Android ads running using the 'new' Google play services library. Most of these will have you chasing your tail adding jar files to the 'libs' folder and adding references to the libraries found inside these jar files within your project settings/structure interfaces. In fact, adding Google ads to an Android project via Android Studio requires:

1)这个元标记添加到您的Andr​​oid清单文件 - 它可以打开的应用程序XML标记的文字之间,第一个(主)活动XML标记之前(去,如上述问题表示,将是错误最初红色 - 我们会解决这个问题的另一个步骤):

1) Add this meta tag to your Android manifest file - it can go between the opening "Application" xml tag and before the first (main) "Activity" xml tag (the text, as indicated in the question above, will be error red initially - we'll fix that in another step):

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

2)本次活动添加到您的Andr​​oid清单文件:

2) Add this activity to your Android manifest file:

    <activity android:name="com.google.android.gms.ads.AdActivity"          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

3)你的的build.gradle文件(一个在项目文件夹,而不是一个在根文件夹 - 例如,一个在网上与你的SRC文件夹中,而不是一个在网上与你的包名的文件夹),将其添加到相关性组(这是缓解)的问题描述的错误步骤:

3) To your "build.gradle" file (the one in your project folder, not the one in the root folder - i.e., the one in-line with your "src" folder, not the one in-line with your package name folder), add this to the "dependencies" group (this is the step that alleviates the error described in the question):

compile 'com.google.android.gms:play-services:4.0.30'

4)Minimim目标SDK是9+,目标是13 +。

4) Minimim target SDK is 9+, target is 13+.

5)使用com.google.android.gms.ads.AdView,而不是com.google.gms.ads ......小部件。

5) Use "com.google.android.gms.ads.AdView" rather than the "com.google.gms.ads..." widgets.

6)无论是在code(下面的示例)或XML布局,实例化AdView中和,你打电话之前mAdView.loadAd(AdRequest中);,一定要设置:

6) Either in code (example below) or in xml layout, instantiate the AdView and, before you call "mAdView.loadAd(adRequest);", be certain to set:

    mAdView.setAdSize(AdSize.BANNER); // Or whatever size you like
    mAdView.setAdUnitId("YOUR_AD_UNIT_ID"); //  Use your ID, requires an AdMob account

7)如果你是编码在MacOS,你从50得到一个编译器更新错误(更新至51,例如),那么你使用的是Java 6.0 SDK编译 - 这是一个问题,因为Android的工作室将只运行6.0,但某些可能会添加AdView的库(审查这个答案旁边的最后一节),都需要一个7.0编译器。这确实是一个非问题在这里(按给出了最后一节的说明),但这里是使用Java 7 SDK编译一个很好的资源 - 按照这些指示,然后重新启动Android和让它重新安装6 SDK其业务需求:的http://www.cc.gatech.edu/~simpkins/teaching/gatech/cs2340/guides/java7-macosx.html

最后,如果你一直追着你的尾巴,并添加JAR / lib中设置如上所述,在编译时,你会得到错误表明您已经复制的AdView / AdRequest中的夹杂物的,等...或者你'重新获得编译器的版本错误(敦促您更新从50到51)。只要删除这些jar / lib中添加和依靠步骤3中的描述的gradle编辑。

Finally, if you've been chasing your tail and added jar/lib settings as described above, when you compile you will get errors indicating that you've duplicated your inclusions of AdView/AdRequest, etc... or if you're getting compiler version errors (urging you to update from 50 to 51). Just delete these jar/lib additions and rely on the gradle edits described in step #3.

这是解决这一问题的官方链接: https://developers.google .COM /移动广告-SDK /文档/

This is the official link that solves this problem: https://developers.google.com/mobile-ads-sdk/docs/

 
精彩推荐
图片推荐