Ad failed to load with error code 0(internal Error) - 华为广告实施
Ad failed to load with error code 0(internal Error) - Huawei Ads Implementation
我在演示应用程序中不断收到上述错误。我有HMS core 5.0.0.329版本(初始版本)。我的互联网连接稳定。我已经在应用程序库上创建了测试应用程序,该应用程序已获得批准但仍然存在相同的错误。还没有运气。
*Note: This Error only occurs on Huawei Device Y6p - Model- MED-LX9 -Android Version -10.
Ads Showing on Samsung S7 - Android Version - 7.0
以下是我的测试应用程序的代码。我正在使用 Android studio Arctic Fox 2020.3.1
Module.gradle:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.huawei.agconnect'
}
android {
compileSdk 30
defaultConfig {
applicationId "com.example.huaweitestads"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Huawei Dependency
implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300'
implementation 'com.huawei.hms:ads-lite:13.4.45.308'
//implementation 'com.huawei.hms:ads:3.4.45.308'
implementation 'com.huawei.hms:ads-identifier:3.4.34.301'
}
Project.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
jcenter() // Warning: this repository is going to shut down soon
maven {url 'https://developer.huawei.com/repo/'}
}
}
rootProject.name = "HuaweiTestAds"
include ':app'
MainActivity:
class MainActivity : AppCompatActivity() {
private val adListener: AdListener = object : AdListener(){
override fun onAdClosed() {
showToast("Ad closed")
}
override fun onAdFailed(p0: Int) {
showToast(String.format(Locale.ROOT, "Ad failed to load with error code %d.", p0))
}
override fun onAdLeave() {
showToast("Ad Leave")
}
override fun onAdOpened() {
showToast(String.format("Ad opened "))
}
override fun onAdLoaded() {
showToast("Ad loaded.")
}
override fun onAdClicked() {
showToast("Ad clicked")
}
override fun onAdImpression() {
showToast("Ad Impression")
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//initialize the Huawei Ads
HwAds.init(this)
val bannerView: BannerView? = findViewById(R.id.hw_banner_view)
bannerView!!.adListener = adListener
bannerView.setBannerRefresh(30)
val adParam = AdParam.Builder().build()
bannerView.loadAd(adParam)
}
private fun showToast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
}
activity.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:hwads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.huawei.hms.ads.banner.BannerView
android:id="@+id/hw_banner_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView"
hwads:adId="testw6vs28auh3"
hwads:bannerSize="BANNER_SIZE_320_50" />
</androidx.constraintlayout.widget.ConstraintLayout>
logCat Exception:
2021-08-27 15:11:48.642 20928-20928/? E/LoadedApk: Unable to
instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip
file
"/data/app/com.huawei.appmarket-KidEWN7eyzOMAnU7Zs1jjg==/base.apk"],nativeLibraryDirectories=[/data/app/com.huawei.appmarket-KidEWN7eyzOMAnU7Zs1jjg==/lib/arm,
/data/app/com.huawei.appmarket-KidEWN7eyzOMAnU7Zs1jjg==/base.apk!/lib/armeabi-v7a,
/system/lib, /hw_product/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:209)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:270)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:922)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:1044)
at android.app.LoadedApk.getResources(LoadedApk.java:1293)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2610)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2598)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7222)
at android.app.ActivityThread.access00(ActivityThread.java:308)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2295)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8349)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
异常 2:
2021-08-27 15:11:31.275 20725-20779/? E/ServiceRegistrarParser: get
ServiceDiscovery
exception.ComponentInfo{com.huawei.hms.agclink/com.huawei.agconnect.core.ServiceDiscovery}
2021-08-27 15:11:31.298 17647-18622/? E/fwkit_kitProviderDispatcher:
[E/fwkit/fwkit_kitProviderDispatcher 17647:4417
StubContentProvider.java:153] NameNotFoundException
android.content.pm.PackageManager$NameNotFoundException
at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:201)
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:170)
at com.huawei.hms.fwkit.kams.provideragent.a.a(KitProviderDispatcher.java:387)
at com.huawei.hms.fwkit.kams.provideragent.a.a(KitProviderDispatcher.java:320)
at com.huawei.hms.fwkit.kams.provideragent.StubContentProvider.getType(StubContentProvider.java:153)
at android.content.ContentProvider$Transport.getType(ContentProvider.java:295)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:140)
at android.os.Binder.execTransactInternal(Binder.java:1028)
at android.os.Binder.execTransact(Binder.java:1001)
异常 3:
2021-08-27 15:12:07.512 4661-4736/? E/PushLog110102300:
[SocketRead_15:10:54-308]read socket occurs
Exception: com.huawei.android.pushagent.datatype.exception.PushException
ra nra* Ei
ee.ck(Unknown Source:101)
ee.run(Unknown Source:40)
任何帮助都是 appreciated.Thanks
如Docs所述,要在targetSdkVersion 28或更高版本的设备上允许HTTP和HTTPS网络请求,请在AndroidManifest.xml
文件中配置以下信息:
<application
...
android:usesCleartextTraffic="true"
>
...
</application>
然后将Gradle中的targetSdk 30改成29.
推荐版本如link
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId ""
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
华为Y6p之前在这个设备上遇到过同样的问题。您可以查看是否有SIM卡。
插入SIM卡后,会读取SIM卡的国家代码。
国家码获取规则:发货地国家码>sim卡国家码>手机设置的国家phone.
我在演示应用程序中不断收到上述错误。我有HMS core 5.0.0.329版本(初始版本)。我的互联网连接稳定。我已经在应用程序库上创建了测试应用程序,该应用程序已获得批准但仍然存在相同的错误。还没有运气。
*Note: This Error only occurs on Huawei Device Y6p - Model- MED-LX9 -Android Version -10. Ads Showing on Samsung S7 - Android Version - 7.0
以下是我的测试应用程序的代码。我正在使用 Android studio Arctic Fox 2020.3.1
Module.gradle:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.huawei.agconnect'
}
android {
compileSdk 30
defaultConfig {
applicationId "com.example.huaweitestads"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Huawei Dependency
implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300'
implementation 'com.huawei.hms:ads-lite:13.4.45.308'
//implementation 'com.huawei.hms:ads:3.4.45.308'
implementation 'com.huawei.hms:ads-identifier:3.4.34.301'
}
Project.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
jcenter() // Warning: this repository is going to shut down soon
maven {url 'https://developer.huawei.com/repo/'}
}
}
rootProject.name = "HuaweiTestAds"
include ':app'
MainActivity:
class MainActivity : AppCompatActivity() {
private val adListener: AdListener = object : AdListener(){
override fun onAdClosed() {
showToast("Ad closed")
}
override fun onAdFailed(p0: Int) {
showToast(String.format(Locale.ROOT, "Ad failed to load with error code %d.", p0))
}
override fun onAdLeave() {
showToast("Ad Leave")
}
override fun onAdOpened() {
showToast(String.format("Ad opened "))
}
override fun onAdLoaded() {
showToast("Ad loaded.")
}
override fun onAdClicked() {
showToast("Ad clicked")
}
override fun onAdImpression() {
showToast("Ad Impression")
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//initialize the Huawei Ads
HwAds.init(this)
val bannerView: BannerView? = findViewById(R.id.hw_banner_view)
bannerView!!.adListener = adListener
bannerView.setBannerRefresh(30)
val adParam = AdParam.Builder().build()
bannerView.loadAd(adParam)
}
private fun showToast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
}
activity.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:hwads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.huawei.hms.ads.banner.BannerView
android:id="@+id/hw_banner_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView"
hwads:adId="testw6vs28auh3"
hwads:bannerSize="BANNER_SIZE_320_50" />
</androidx.constraintlayout.widget.ConstraintLayout>
logCat Exception: 2021-08-27 15:11:48.642 20928-20928/? E/LoadedApk: Unable to instantiate appComponentFactory java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/com.huawei.appmarket-KidEWN7eyzOMAnU7Zs1jjg==/base.apk"],nativeLibraryDirectories=[/data/app/com.huawei.appmarket-KidEWN7eyzOMAnU7Zs1jjg==/lib/arm, /data/app/com.huawei.appmarket-KidEWN7eyzOMAnU7Zs1jjg==/base.apk!/lib/armeabi-v7a, /system/lib, /hw_product/lib, /system/product/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:209) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.app.LoadedApk.createAppFactory(LoadedApk.java:270) at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:922) at android.app.LoadedApk.getClassLoader(LoadedApk.java:1044) at android.app.LoadedApk.getResources(LoadedApk.java:1293) at android.app.ContextImpl.createAppContext(ContextImpl.java:2610) at android.app.ContextImpl.createAppContext(ContextImpl.java:2598) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7222) at android.app.ActivityThread.access00(ActivityThread.java:308) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2295) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8349) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
异常 2:
2021-08-27 15:11:31.275 20725-20779/? E/ServiceRegistrarParser: get ServiceDiscovery exception.ComponentInfo{com.huawei.hms.agclink/com.huawei.agconnect.core.ServiceDiscovery} 2021-08-27 15:11:31.298 17647-18622/? E/fwkit_kitProviderDispatcher: [E/fwkit/fwkit_kitProviderDispatcher 17647:4417 StubContentProvider.java:153] NameNotFoundException android.content.pm.PackageManager$NameNotFoundException at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:201) at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:170) at com.huawei.hms.fwkit.kams.provideragent.a.a(KitProviderDispatcher.java:387) at com.huawei.hms.fwkit.kams.provideragent.a.a(KitProviderDispatcher.java:320) at com.huawei.hms.fwkit.kams.provideragent.StubContentProvider.getType(StubContentProvider.java:153) at android.content.ContentProvider$Transport.getType(ContentProvider.java:295) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:140) at android.os.Binder.execTransactInternal(Binder.java:1028) at android.os.Binder.execTransact(Binder.java:1001)
异常 3:
2021-08-27 15:12:07.512 4661-4736/? E/PushLog110102300: [SocketRead_15:10:54-308]read socket occurs Exception: com.huawei.android.pushagent.datatype.exception.PushException ra nra* Ei ee.ck(Unknown Source:101) ee.run(Unknown Source:40)
任何帮助都是 appreciated.Thanks
如Docs所述,要在targetSdkVersion 28或更高版本的设备上允许HTTP和HTTPS网络请求,请在AndroidManifest.xml
文件中配置以下信息:
<application
...
android:usesCleartextTraffic="true"
>
...
</application>
然后将Gradle中的targetSdk 30改成29.
推荐版本如link
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId ""
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
华为Y6p之前在这个设备上遇到过同样的问题。您可以查看是否有SIM卡。
插入SIM卡后,会读取SIM卡的国家代码。 国家码获取规则:发货地国家码>sim卡国家码>手机设置的国家phone.