我在演示应用程序中不断收到上述错误。我有 HMS 核心版本 5.0.0.329(初始版本)。我的互联网连接很稳定。我已经在应用程序库上创建了测试应用程序,该应用程序已获批准但仍然存在相同的错误。还没有运气。
*注意:此错误仅发生在华为设备 Y6p - 型号 - MED-LX9 -Android 版本 -10 上。三星 S7 上显示的广告 - Android 版本 - 7.0
以下是我的测试应用程序的代码。我正在使用 Android Studio 北极狐 2020.3.1
模块.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'
}
项目.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
}
设置.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'
主要活动:
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()
}
}
活动.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 异常:2021-08-27 15:11:48.642 20928-20928/? E / LoadedApk:无法实例化appComponentFactory java.lang.ClassNotFoundException:在路径上找不到类“androidx.core.app.CoreComponentFactory”:DexPathList [[zip文件“/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]] 在 dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:209) 在 java.lang.ClassLoader.loadClass(ClassLoader. java:379) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:312) 在 android.app.LoadedApk.createAppFactory(LoadedApk.java:270) 在 android.app.LoadedApk。
例外 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) 在 com.huawei.hms.fwkit.kams.provideragent.aa(KitProviderDispatcher.java:387) 在 com.huawei.hms.fwkit.kams.provideragent.aa(KitProviderDispatcher.java:320) ) 在 com.huawei.hms.fwkit.kams.provideragent.StubContentProvider.getType(StubContentProvider.java:
例外 3:
2021-08-27 15:12:07.512 4661-4736/? E/PushLog110102300:[SocketRead_15:10:54-308]读取套接字发生异常:com.huawei.android.pushagent.datatype.exception.PushException r a n r a* E i ee.ck(Unknown Source:101) ee。运行(未知来源:40)
任何帮助将不胜感激。谢谢