我正在尝试将mopub添加到我的应用中。我通过AndroidStudio插件安装了sdk。并将其添加到我的xml
<com.mopub.mobileads.mopubview
android:id="@+id/adview"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="50dp">
</com.mopub.mobileads.mopubview>
但它给了我这些错误:
The following classes could not be found:
- com.mopub.mobileads.mopubview (Fix Build Path, Create Class)
当我运行应用程序时,它会崩溃:
java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.hroshandel.myapplication / com.example.hroshandel.myapplication.SimpleIntro_FragmentActivity}:android.view.InflateException:二进制XML文件行#15:错误膨胀类com.mopub.mobileads.mopubview
引起:android.view.InflateException:二进制XML文件行#15:错误膨胀类com.mopub.mobileads.mopubview
at com.example.hroshandel.myapplication.SimpleIntro_FragmentActivity.onCreate(SimpleIntro_FragmentActivity.java:20)
引起:java.lang.ClassNotFoundException:在路径上找不到类“com.mopub.mobileads.mopubview”:DexPathList [[zip file“/data/app/com.example.hroshandel.myapplication-4。 apk“],nativeLibraryDirectories = [/ data / app-lib / com.example.hroshandel.myapplication-4,/ vendor / lib,/ system / lib]]
答案 0 :(得分:8)
请检查班级名称的错字,在文档中写一个天才:
<com.mopub.mobileads.mopubview
android:id="@+id/adview"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="50dp">
</com.mopub.mobileads.mopubview>
但是正确的班级名称是:
<com.mopub.mobileads.MoPubView> ... </com.mopub.mobileads.MoPubView>
答案 1 :(得分:3)
似乎你必须按照上面的回答中的说明修改你的gradle。但除此之外我运行应用程序时出现了相同的错误消息,这是我能够绕过它的方式:
<com.mopub.mobileads.mopubview
android:id="@+id/adview"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="50dp">
</com.mopub.mobileads.mopubview>
<FrameLayout
android:id="@+id/adContainer"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="50dp">
</FrameLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics()); // optional library
setContentView(R.layout.main_activity);
ButterKnife.inject(this); // optional, used to inject views e.g. adContainer
MoPubView moPubView = new MoPubView(this);
moPubView.setAdUnitId("ad unit id");
moPubView.loadAd();
moPubView.setBannerAdListener(new MoPubView.BannerAdListener() {
@Override
public void onBannerLoaded(MoPubView moPubView) {
Log.d(TAG, "Banner loaded");
try {
mAdContainer.addView(moPubView);
}
catch(Exception ex){
Log.d(TAG, "Error loading banner add to container");
}
}
@Override
public void onBannerFailed(MoPubView moPubView, MoPubErrorCode moPubErrorCode) {
Log.d(TAG, "Banner failed");
}
@Override
public void onBannerClicked(MoPubView moPubView) {
Log.d(TAG, "Banner clicked");
}
@Override
public void onBannerExpanded(MoPubView moPubView) {
Log.d(TAG, "Banner expanded");
}
@Override
public void onBannerCollapsed(MoPubView moPubView) {
Log.d(TAG, "Banner collapsed");
}
});
答案 2 :(得分:0)
您是否遵循了设置流程https://dev.twitter.com/mopub/android/getting-started
的明显问题编辑:
有GRADLE
复制到您的项目
$MY_PROJECT_DIR $ mkdir mopub-sdk
$MY_PROJECT_DIR $ cp -R $MOPUB_DIR/mopub-android-sdk/mopub-sdk mopub-sdk
添加到build.gradle
include ':app', ':mopub-sdk'
dependencies { compile project(':mopub-sdk') }