gpt4 book ai didi

android - 将 Google Play 服务库添加到现有库项目

转载 作者:行者123 更新时间:2023-11-29 16:00:47 25 4
gpt4 key购买 nike

在我的应用程序(主项目)中,我添加了 3 个现有项目标记为库,所有这 3 个项目(库)都需要 GooglePlayServiceLibrary 以便它们可以运行 AdMob 和插页式广告。

我已经在我的主项目中成功添加了这 3 个库项目,当我启动我的 <来 self 的主要项目 Activity 的 strong>library 项目。但是当我将 GooglePlayServiceLibrary 添加到这 3 个项目并尝试运行它们时,我遇到了错误。

库项目的XML代码:

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
ads:adSize="SMART_BANNER"
ads:adUnitId="myadId" />

库项目Java代码:

AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("").build();
adView.loadAd(adRequest);

库项目 list 文件:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|smallestScreenSize|uiMode|screenLayout|screenSize"/>
<activity
android:name="com.pkg.Interstitial"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent" />

我还附上了我的 LogCat:

07-15 04:12:41.630: E/AndroidRuntime(1301): FATAL EXCEPTION: main
07-15 04:12:41.630: E/AndroidRuntime(1301): Process: com.main.project, PID: 1301
07-15 04:12:41.630: E/AndroidRuntime(1301): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.main.project/com.library.project.MainActivity}: android.view.InflateException: Binary XML file line #187: Error inflating class com.google.android.gms.ads.AdView
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.os.Handler.dispatchMessage(Handler.java:102)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.os.Looper.loop(Looper.java:136)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-15 04:12:41.630: E/AndroidRuntime(1301): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 04:12:41.630: E/AndroidRuntime(1301): at java.lang.reflect.Method.invoke(Method.java:515)
07-15 04:12:41.630: E/AndroidRuntime(1301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-15 04:12:41.630: E/AndroidRuntime(1301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-15 04:12:41.630: E/AndroidRuntime(1301): at dalvik.system.NativeStart.main(Native Method)
07-15 04:12:41.630: E/AndroidRuntime(1301): Caused by: android.view.InflateException: Binary XML file line #187: Error inflating class com.google.android.gms.ads.AdView
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-15 04:12:41.630: E/AndroidRuntime(1301): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.Activity.setContentView(Activity.java:1929)
07-15 04:12:41.630: E/AndroidRuntime(1301): at com.library.project.MainActivity.onCreate(MainActivity.java:75)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.Activity.performCreate(Activity.java:5231)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-15 04:12:41.630: E/AndroidRuntime(1301): ... 11 more
07-15 04:12:41.630: E/AndroidRuntime(1301): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.AdView" on path: DexPathList[[zip file "/data/app/com.main.project-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.main.project-1, /system/lib]]
07-15 04:12:41.630: E/AndroidRuntime(1301): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-15 04:12:41.630: E/AndroidRuntime(1301): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
07-15 04:12:41.630: E/AndroidRuntime(1301): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
07-15 04:12:41.630: E/AndroidRuntime(1301): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
07-15 04:12:41.630: E/AndroidRuntime(1301): ... 21 more

请告诉我如何在我的图书馆项目中使用这些广告。

提前致谢

最佳答案

您需要在您的Main Project 中创建一个libs/文件夹,并将GooglePlayServiceLibraryJAR 文件物理地放入该项目中,然后添加该 Jar 文件到 Java Build Path,您必须在 Order and Export 中Check Mark SDK jar。这必须在您的主项目中完成,并在 list 文件中为 GooglePlayServicesLibrary 添加元数据,并在我们的主项目 list 中定义这样的 Activity 名称。

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

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

另外不要忘记添加每个权限服务接收在您的库项目中使用的所有内容,所有这些都应该在主项目的 list 中用它们的包名称定义。

我也遇到了同样的问题,这就是我解决它的方式......干杯

关于android - 将 Google Play 服务库添加到现有库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24750009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com