问题
My Android app did work well (API 15) untill I wanted to include Google ads. Although google-play-services.jar is in my project library and it contains com.google.android.gms.ads, the debugger comes up with an error: package com.google.android.gms.ads does not exist when using:
import com.google.android.gms.ads.*;
I tried several solutions, but none of them worked. I changed from Android 4.03 API15 to Google API15 but nothing changed. What am I doing wrong?
回答1:
You must import google-play-services_lib that is located in the folder <android-sdk-directory>/extras/google/google_play_services/libproject/google-play-services_lib
and declare it as library of your project.
You will find more informations on Set Up Google Play Services SDK.
回答2:
There might be several years have been already gone but no good solution. So, someone like me facing the same trouble till today. I have solved it by the following method (check the attached figure)-
Add the marked line in the gradle
Add the following code in the gradle.
implementation 'com.google.android.gms:play-services-ads:11.8.0'
回答3:
I had this problem when building an ionic cordova project after adding the plugin admob-google-cordova
and running ionic cordova build
. For me I went into my project.properties
(platforms/android/project.properties
) file and changed the line from cordova.system.library.1=com.google.android.gms:play-services-ads:+
into cordova.system.library.1=com.google.android.gms:play-services-ads:9.8.0
.
来源:https://stackoverflow.com/questions/20403136/error-package-com-google-android-gms-ads-does-not-exist