【发布时间】:2016-08-26 22:17:12
【问题描述】:
我想将 admob 集成到我的应用程序中。我正在尝试在https://firebase.google.com/docs/admob/android/quick-start 运行测试代码。
我当前的 google-play-service 版本是 32。以前我正在研究版本 29。由于 google 已将 play_service 库拆分为多个库,我曾经在 m2repository 的每个库存储中选择和提取。目前我选择了 play-services-ads-lite-9.0.0 .jar。这是我在项目中包含的唯一 jar 文件。当我运行代码时,应用程序崩溃。编译器中没有警告或错误。
我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.richa.salemob"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="23"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:allowBackup="true"
android:theme="@android:style/Theme.Black.NoTitleBar">
<activity android:name=".Start">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application></manifest>
我的布局 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.richa.salesmob"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
我的 Java 代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
MobileAds.initialize(StartFields.context, "ca-app-pub-3940256099942544~3347511713");
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new
AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
adView.loadAd(adRequest);
init();
}
我无法理解并解决错误: java.lang.ClassNotFoundException:在路径上找不到类“com.google.android.gms.R$styleable”:DexPathList [[zip 文件“/data/app/com.richa.India_Sales-1/base.apk” ],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
请帮忙。谢谢
【问题讨论】:
-
粘贴gradle文件
-
我没有 gradle 文件。我正在为 Api 级别 9 编写此代码,这是 AdMob 使用 Intellij 作为普通 android 应用程序所需的最低要求。
-
11 小时仍然没有任何答案 :( 请有人看看
-
您应该尝试使用android studio 来制作android 应用程序,这将帮助您更轻松地编译dependencies。添加 google-play-service 和使用 adMob 所需的所有依赖项。希望对您有所帮助!
-
我现在不想使用 Gradle,请看这个link,它对我的问题的详细解释
标签: android admob google-play-services