I m getting the above error continuously in demo Application. I have HMS core Version 5.0.0.329(Initial Version). My internet connection is stable. I have created test application on app gallery that has been approved but still same error. No luck yet.
*Note: This Error only occurs on Huawei Device Y6p – Model- MED-LX9 -Android Version -10.
Ads Showing on Samsung S7 – Android Version – 7.0
Following is the code for my test application. I m using 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.access$2400(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)
Exception 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)
Exception 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)
Any help would be appreciated.Thanks
3
Answers
As Docs mentioned, To allow HTTP and HTTPS network requests on devices with targetSdkVersion 28 or later, pls configure the following information in the
AndroidManifest.xml
file:Then change targetSdk 30 in Gradle to 29.
recommended versions are as in the link
Huawei Y6p has encountered the same problem before on this device. You can check there is a SIM card.
After the SIM is inserted, the country code of the SIM card will be read.
Rules for obtaining the country code: country code of the place of shipment> country code of the sim card> country set by the mobile phone.