Androidアプリ:ClassNotFoundExceptionエラー
Google Play Consoleのクラッシュ報告で、「ClassNotFoundException(ac.loadClass)」というログが表示されていたので、調べました。
恐らくAdmobのSDKのエラー
エラーレポートを見ると、
java.lang.NoClassDefFoundError:
com.google.android.gms.policy_ads_fdr_dynamite@~
というログがいくつも出力されていました。
調べてみると、Admobの全画面広告表示時に読込がうまく行かず落ちてしまうときにこのログが出力されているようです。
build.gradle(Module.app)において、
implementation ‘com.google.android.gms:play-services-ads:17.0.0’
を指定している場合に起こるようです。
このエラーは17.2.0現在も発生しています。
(※18.0.0でも同様にエラーが発生します)
解決方法はAdMobの方での対応待ち、というような情報が散見されており、2019年5月5日現在、解決方法が見つかっていません。
解決方法が分かり次第、更新します。
解決方法?
2019年6月27日現在、上記の問題はplay-services-ads:18.0.0でも発生しています。
しかし、以下の方法で解決するかも、という情報がありましたので記します。
build.gradle(app)のandroid{}の中のdefaultConfig{}に以下の一文を追加します。
useLibrary ‘org.apache.http.legacy’
以下のようになります。
android {
compileSdkVersion 28
defaultConfig {
applicationId “***.******.*****”
minSdkVersion 16
targetSdkVersion 28
versionCode 16
versionName “16”
testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”
useLibrary ‘org.apache.http.legacy’
}
次に、AndroidManifext.xmlの<application>タグ内に以下の1文を追加します。
<uses-library android:name=”org.apache.http.legacy” android:required=”false” />
以下のようになります。
<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”><meta-data
android:name=”com.google.android.gms.ads.APPLICATION_ID”
android:value=”ca-app-pub-5671510467275757~3119478397″
/>
<uses-library android:name=”org.apache.http.legacy” android:required=”false” /><activity
android:name=”.MainActivity”
android:screenOrientation=”portrait”>
<intent-filter>
<action android:name=”android.intent.action.MAIN”/>
<category android:name=”android.intent.category.LAUNCHER”/>
</intent-filter>
</activity></application>
この設定の後、上記のエラーは発生していませんが、まだ修正してから日数が浅井ため、なんとも言えません。
1か月経ってもエラーが1件も出ていなければ、その旨をここで報告します。
関連記事