找不到类'com.google.android.gms.ads.AdView

时间:2013-12-15 22:34:37

标签: android admob

我正在使用Android Studio。我已将 googleAdMobAdsdk6-4-1.jar 添加到我之前添加的libs文件夹中的项目中。我可以扩展库文件并实际导航到AdView类。它编译没有问题但是当我运行它崩溃。任何帮助表示赞赏。

12-15 21:35:40.581    5375-5375/? E/dalvikvm﹕ Could not find class 'com.google.android.gms.ads.AdView', referenced from method net.kritico.todolist.ToDoListActivity.onCreate
12-15 21:35:40.581    5375-5375/? W/dalvikvm﹕ VFY: unable to resolve new-instance 996 (Lcom/google/android/gms/ads/AdView;) in Lnet/kritico/todolist/ToDoListActivity;
12-15 21:35:40.581    5375-5375/? D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0037
12-15 21:35:40.585    5375-5375/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x2034 at 0x39 in Lnet/kritico/todolist/ToDoListActivity;.onCreate
12-15 21:35:40.585    5375-5375/? I/dalvikvm﹕ DexOpt: unable to optimize static field ref 0x0b0b at 0x47 in Lnet/kritico/todolist/ToDoListActivity;.onCreate
12-15 21:35:40.585    5375-5375/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x2031 at 0x5c in Lnet/kritico/todolist/ToDoListActivity;.onCreate
12-15 21:35:40.597    5375-5375/? I/dalvikvm﹕ DexOpt: unable to optimize static field ref 0x0b0a at 0x5f in Lnet/kritico/todolist/ToDoListActivity;.onCreate
12-15 21:35:40.765    5375-5375/? D/AndroidRuntime﹕ Shutting down VM
12-15 21:35:40.765    5375-5375/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa617b908)
12-15 21:35:40.789    5375-5375/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{net.kritico.todolist/net.kritico.todolist.ToDoListActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)

3 个答案:

答案 0 :(得分:0)

您的XML引用了Google Play服务库中包含的com.google.android.gms.ads.AdView(请参阅stacktrace),以及Admob现在的打包方式。

但是你已经包含了Admob-6.4.1,它是旧的Admob SDK和Admob类,它们位于不同的包中,并且签名略有不同。

从您的项目中删除Admob-6.4.1并改为使用Google Play服务。

请参阅https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play

答案 1 :(得分:0)

从libs文件夹中删除jar(现在不推荐使用sdk)。您应该使用Google Play服务。

取出罐子后。清理您的项目,并在应用级dependencies中的build.gradle下添加以下内容。

compile 'com.google.android.gms:play-services-ads:8.4.0'

根据提示同步您的项目,之后您应该好好去。

答案 2 :(得分:0)

使用此最新库:

rem This sets the variable DIR to the current directory with the jar artifact
set DIR=%~dp0

rem This creates a temporary mod file
D:\jdks\jdk11\bin\jmod create --class-path %DIR%app.jar %DIR%temp.mod

rem This creates distributable JRE
D:\jdks\jdk11\bin\jlink ^
--compress=2 ^
--strip-debug ^
--no-man-pages ^
--launcher run=com.epsilon/com.epsilon.Main ^
--module-path D:\jdks\jdk11\jmods;D:\jdks\jfx11\jmods;%DIR% ^
--add-modules com.epsilon ^
--output %DIR%dist

rem This command deletes the temporary mod file
del %DIR%temp.mod

rem You can create a shortcut to your app above the "dist" folder and enter the below line to the shortcut's target property
rem %windir%\system32\cmd.exe /c start "" "%CD%\dist\bin\javaw.exe" -m com.epsilon/com.epsilon.Main

随时阅读admob文档

<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteBase "/"

 RewriteCond %{HTTPS} off
 RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
 RewriteRule ^(comments)($|/) - [L]
 RewriteCond %{REQUEST_URI} !^public
 RewriteRule ^(.*)$ public/$1 [L]
 # RewriteRule ^/news$ /public/index.php/news$ [NC]
</IfModule>