在将应用程序放到应用程序商店之前,我正试图在我的应用程序上放置广告。
我按照这里的教程>>> https://developers.google.com/admob/android/quick-start#load_the_ad_in_the_mainactivity_class<<<
我在发布时遇到错误:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 2
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
这是我的代码:
的build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}
的strings.xml
<resources>
<string name="app_name">Fact App</string>
<string name="settings">Settings</string>
<string name="about">About</string>
<string name="rate">Rate us!</string>
<string name="home">Home</string>
<string name="banner_ad_unit_id"> ca-app-pub-1257847978838563/3917394334</string>
</resources>
activity_main.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>
MainActivity
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
factBox = (TextView) findViewById(R.id.factTextBox);
factNumberBox = (TextView) findViewById(R.id.numberBox);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
有人知道我为什么会收到此错误吗?
答案 0 :(得分:0)
看起来您缺少以下gradle依赖项:
compile 'com.google.android.gms:play-services-ads:8.4.0'