2
好吧,所以我正在開發一個Android應用程序,並且正在嘗試將廣告放入其中,但當我嘗試編譯它時,出現錯誤「Can not resolve symbol'MobileAds'」 。無法解析符號'MobileAds'
這是我有:
activity_main.java
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends ListActivity {
private ArrayList<Sound> mSounds = null;
private SoundAdapter mAdapter = null;
static MediaPlayer mMediaPlayer = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-Removed");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
我的XML:
xmlns:ads="http://schemas.android.com/apk/res-auto"
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
而且
<string name="banner_ad_unit_id">ca-app-pub-(removed)</string>
項目搖籃
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
App Gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-ads:9.6.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
爲什麼我會收到此錯誤消息? 對此的任何幫助表示讚賞。謝謝!
看看'MainActivity'中的'import'語句。你有'MobileAds'導入嗎? –
Agh ...大聲笑感謝這麼多的伴侶! – Freeman