【问题标题】:Implement AdMob service in Unity在 Unity 中实施 AdMob 服务
【发布时间】:2016-03-22 12:12:51
【问题描述】:

我正在尝试在 Unity 项目中添加 AdMob 服务。对于 IOS 设备,它运行良好。但是对于Android设备,它会输出编译错误。

我所做的是:

  1. 获取 AdMob 单元 ID 并将其粘贴到源代码 (C#)。
  2. 将 AdMob Unity 插件导入 Unity。
  3. 将 google-play-services_lib 导入 Asset/Plugins/Android 文件夹。

我尝试删除并重新导入包并删除临时文件夹。但是还是不行。

我该如何解决这个问题?

这是日志:

CommandInvokationFailure: Failed to re-package resources. See the Console for details.

/Users/kazuhiko/Library/Android/sdk/build-tools/23.0.2/aapt package --auto-add-overlay -v -f -m -J gen -M AndroidManifest.xml -S "res" -I "/Users/kazuhiko/Library/Android/sdk/platforms/android-23/android.jar" -F bin/resources.ap_ --extra-packages com.google.unity:android.support.v7.appcompat:com.google.android.gms:com.google.android.gms.ads:com.google.android.gms:android.support.v4 -S "/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res" -S "/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res" -S "/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/play-services-ads-8.4.0/res" -S "/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/play-services-basement-8.4.0/res" -S "/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/support-v4-23.1.1/res"

stderr[

/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_alert_dialog_button_bar_material.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:layoutDirection from <android.support.v7.widget.ButtonBarLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_alert_dialog_button_bar_material.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/abc_alert_dialog_button_bar_material for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_alert_dialog_material.xml:48: note: removing attribute http://schemas.android.com/apk/res/android:textAlignment from <android.support.v7.widget.DialogTitle>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_alert_dialog_material.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/abc_alert_dialog_material for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_dialog_title_material.xml:29: note: removing attribute http://schemas.android.com/apk/res/android:textAlignment from <TextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_dialog_title_material.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/abc_dialog_title_material for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_screen_toolbar.xml:27: note: removing attribute http://schemas.android.com/apk/res/android:touchscreenBlocksFocus from <android.support.v7.widget.ActionBarContainer>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_screen_toolbar.xml: note: using v21 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/abc_screen_toolbar for configuration v21.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_search_view.xml:47: note: removing attribute http://schemas.android.com/apk/res/android:layoutDirection from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/abc_search_view.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/abc_search_view for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media.xml:42: note: removing attribute http://schemas.android.com/apk/res/android:layoutDirection from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media.xml:34: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginStart from <include>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media.xml:34: note: removing attribute http://schemas.android.com/apk/res/android:layout_toStartOf from <include>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/notification_template_big_media for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media_narrow.xml:60: note: removing attribute http://schemas.android.com/apk/res/android:layout_toEndOf from <ImageView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media_narrow.xml:46: note: removing attribute http://schemas.android.com/apk/res/android:layout_toEndOf from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media_narrow.xml:46: note: removing attribute http://schemas.android.com/apk/res/android:layoutDirection from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media_narrow.xml:38: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginStart from <include>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media_narrow.xml:38: note: removing attribute http://schemas.android.com/apk/res/android:layout_toStartOf from <include>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media_narrow.xml:30: note: removing attribute http://schemas.android.com/apk/res/android:layout_alignParentEnd from <include>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_big_media_narrow.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/notification_template_big_media_narrow for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_lines.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:paddingEnd from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_lines.xml:77: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginStart from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_lines.xml:96: note: removing attribute http://schemas.android.com/apk/res/android:paddingStart from <TextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_lines.xml:64: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginStart from <TextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_lines.xml:27: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginStart from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_lines.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/notification_template_lines for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_media.xml:43: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginEnd from <include>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_media.xml:33: note: removing attribute http://schemas.android.com/apk/res/android:layoutDirection from <LinearLayout>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_media.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/notification_template_media for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_part_chronometer.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:paddingStart from <Chronometer>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_part_chronometer.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/notification_template_part_chronometer for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_part_time.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:paddingStart from <DateTimeView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/notification_template_part_time.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/notification_template_part_time for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_powered_by_google.xml:28: note: removing attribute http://schemas.android.com/apk/res/android:layout_toEndOf from <ImageView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_powered_by_google.xml:28: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginStart from <ImageView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_powered_by_google.xml:8: note: removing attribute http://schemas.android.com/apk/res/android:layout_marginStart from <View>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_powered_by_google.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/place_autocomplete_item_powered_by_google for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_prediction.xml:52: note: removing attribute http://schemas.android.com/apk/res/android:layout_toEndOf from <TextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_prediction.xml:35: note: removing attribute http://schemas.android.com/apk/res/android:layout_toEndOf from <TextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_prediction.xml:8: note: removing attribute http://schemas.android.com/apk/res/android:layout_alignParentStart from <include>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_item_prediction.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/place_autocomplete_item_prediction for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_progress.xml:2: note: removing attribute http://schemas.android.com/apk/res/android:indeterminateTint from <ProgressBar>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_progress.xml:2: note: removing attribute http://schemas.android.com/apk/res/android:indeterminateTintMode from <ProgressBar>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/layout/place_autocomplete_progress.xml: note: using v21 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/place_autocomplete_progress for configuration v21.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/select_dialog_multichoice_material.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:paddingStart from <CheckedTextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/select_dialog_multichoice_material.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:paddingEnd from <CheckedTextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/select_dialog_multichoice_material.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/select_dialog_multichoice_material for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/select_dialog_singlechoice_material.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:paddingStart from <CheckedTextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/select_dialog_singlechoice_material.xml:18: note: removing attribute http://schemas.android.com/apk/res/android:paddingEnd from <CheckedTextView>
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/appcompat-v7-23.1.1/res/layout/select_dialog_singlechoice_material.xml: note: using v17 attributes; synthesizing resource com.kazzzstudio.androidadmobtest:layout/select_dialog_singlechoice_material for configuration v17.
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/values/admob_ads_attrs.xml:10: error: Attribute "adSize" has already been defined
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/values/admob_ads_attrs.xml:17: error: Attribute "adSizes" has already been defined
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/values/admob_ads_attrs.xml:20: error: Attribute "adUnitId" has already been defined
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/values/common_attrs.xml:13: error: Attribute "imageAspectRatioAdjust" has already been defined
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/values/common_attrs.xml:22: error: Attribute "imageAspectRatio" has already been defined
/Volumes/Time Machine/Dev/Unity/AndroidAdMobTest/Temp/StagingArea/android-libraries/google-play-services_lib/res/values/common_attrs.xml:27: error: Attribute "circleCrop" has already been defined

]
stdout[
Configurations:
 (default)

Files:
  AndroidManifest.xml
    Src: () AndroidManifest.xml

Resource Dirs:
Including resour<message truncated>

【问题讨论】:

  • 我不确定问题出在哪里,但有一些建议,请检查您在 SDK 中的 Google Play 服务版本是否是最新的。
  • error: Attribute "adSize" has already been defined 和类似错误意味着您的项目中包含了两次 admob sdk 库
  • 有时Android包上的统一故障,如果你仍然有问题试试这个:复制你的整个项目(有备份),然后在项目文件夹中删除Libraries文件夹,然后打开那个再次在 Unity 中进行项目(unity 将为您重新生成该文件夹)并尝试构建
  • 我不明白为什么已经定义了属性“adSize”。我试图删除项目中的库文件夹,但它仍然显示相同的错误消息。

标签: android unity3d admob


【解决方案1】:

我可能会解决问题。现在它可以通过构建阶段并安装android模拟器(但是当我启动应用程序时,它总是崩溃)。 我所做的是从 Asset/Plugins/Android/ 文件夹中删除 5 个文件。

  • appcompat-v7-23.1.1.aar
  • play-services-ads-8.4.0.aar
  • play-services-basement-8.4.0.aar
  • support-annotations-23.1.1.jar
  • support-v4-23.1.1.aar

它是由 Unity 自动生成的,删除这些文件并不容易。当我删除这些文件时,Unity 会再次生成这些文件。所以我所做的就是将平台切换到 iOS 并删除文件。再次,我将平台切换到 Android。它运作良好。我不知道这个程序是否正确。因为它不聪明。感谢您对我的善意支持。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 2011-12-15
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多