3

I'm implementing the huawei ads in the android Application. I have go through all the https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/publisher-service-banner-0000001050066915 and successfully implemented the ads but android studio preview is giving me error and is not displaying the preview when adding the huawei ads in the xml. After Removing the Huawei Ads preview is showing.

Following is the my layout:

 <?xml version="1.0" encoding="utf-8"?>
<com.huawei.hms.ads.nativead.NativeView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/native_video_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="#FFFFFF"
    android:orientation="vertical">
    <com.huawei.hms.ads.nativead.MediaView
        android:id="@+id/ad_media"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/_50sdp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:background="@color/white">
        <TextView
            android:id="@+id/ad_title"
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="24dp"
            android:layout_marginTop="16dp"
            android:alpha="1"
            android:textColor="#000000"
            android:textSize="@dimen/hiad_text_13_sp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"/>
        <TextView
            android:id="@+id/ad_source"
            android:layout_width="wrap_content"
            android:layout_height="19dp"
            android:layout_marginStart="24dp"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="16dp"
            android:alpha="0.6"
            android:text="asdfasj"
            android:maxWidth="158dp"
            android:textColor="#666666"
            android:textSize="@dimen/hiad_text_12_sp"
            app:layout_constraintStart_toStartOf="@id/ad_title"
            app:layout_constraintEnd_toStartOf="@id/ad_flag"
            app:layout_constraintTop_toBottomOf="@id/ad_title"
        />

        <TextView
            android:id="@+id/ad_flag"
            android:layout_width="20dp"
            android:layout_height="14dp"
            android:background="@drawable/native_flag_rounded_corners_shape"
            android:text="@string/ad_flag"
            android:textColor="#FFFFFF"
            android:textSize="8sp"
            android:layout_marginStart="@dimen/_10sdp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@id/ad_source"
            app:layout_constraintStart_toEndOf="@id/ad_source"
            app:layout_constraintTop_toTopOf="@id/ad_source" />

        <Button
            android:id="@+id/ad_call_to_action"
            android:layout_width="72dp"
            android:layout_height="26dp"
            android:layout_alignParentEnd="true"
            android:background="@drawable/native_button_rounded_corners_shape"
            android:textColor="#FFFFFF"
            android:textSize="10sp"
            android:layout_marginEnd="@dimen/_20sdp"
            app:layout_constraintBottom_toBottomOf="@+id/ad_source"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</com.huawei.hms.ads.nativead.NativeView>

Following is the error I m encountering with enter image description here When I remove the root tag to Constraint Layout. Preview is visible on Screen and all errors are gone. Inside those two tags I m facing the following Exception:

FirstException: Don't Create Threads in Preview

java.lang.IllegalStateException: It is not allowed to create new threads in the preview   at com.huawei.hms.ads.kn.newThread  at java.util.concurrent.ThreadPoolExecutor$Worker.(ThreadPoolExecutor.java:623)   at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:912)   at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1343)   at com.huawei.hms.ads.km.Code  at com.huawei.hms.ads.km.I  at com.huawei.hms.ads.lj.Code  at com.huawei.hms.ads.lj.V  at com.huawei.hms.ads.dl.Z  at com.huawei.hms.ads.dl.V  at com.huawei.hms.ads.dl.Code  at com.huawei.openalliance.ad.views.PPSNativeView.Code  at com.huawei.openalliance.ad.views.PPSNativeView.  at com.huawei.hms.ads.nativead.NativeView.  at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-2)   at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)   at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)   at java.lang.reflect.Constructor.newInstance(Constructor.java:490)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)   at android.view.LayoutInflater.inflate(LayoutInflater.java:657)   at android.view.LayoutInflater.inflate(LayoutInflater.java:499)

Second Exception: Failed to instantiate One Or more Class The following classes could not be instantiated: - com.huawei.hms.ads.nativead.MediaView (Open Class, Show Exception, Clear Cache) - com.huawei.openalliance.ad.views.VideoView (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout. Exception Details java.lang.NullPointerException   at com.huawei.openalliance.ad.views.NativeVideoView.Code  at com.huawei.openalliance.ad.views.NativeVideoView.  at com.huawei.hms.ads.nativead.MediaView.Code  at com.huawei.hms.ads.nativead.MediaView.  at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-2)   at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)   at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)   at java.lang.reflect.Constructor.newInstance(Constructor.java:490)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1121)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)   at android.view.LayoutInflater.inflate(LayoutInflater.java:680)   at android.view.LayoutInflater.inflate(LayoutInflater.java:499)

I have invalidate the Cache and restart the Android Studio but nothing has worked yet. Can any one help me to render the preview. Any help would be appreciated. Thanks

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
waheed shah
  • 494
  • 7
  • 19
  • 2
    This clearly looks like a bug on the SDK, I suggest you file a ticket to Huawei. – m0skit0 Aug 25 '21 at 08:38
  • Thank you for providing the information regarding this issue, we have reported it to the R & D team, If we need further information or your assistance, will contact you as soon as possible. – zhangxaochen Aug 25 '21 at 08:55

1 Answers1

0

Currently, the Ads kit SDK references the HMS base SDK code, but seems you have not integrate the HMS base SDK.

As a result, this following error occurs during preview.

enter image description here

If you choose not to integrate the HMS base SDK, the Ads SDK function is not affected but will be affected during preview.

So there are two options for your reference : One way is you can try to integrate the hms base sdk, or another way is to ignore this preview error, because this will not affect the actual operation.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • I have the sample application in which i have integrated the HMS base SDK, but still i m getting the Thread exception and preview isn't viewing. Following is the link for the screen shot. https://ibb.co/hCnwfht .. Here is the link when i comment the banner xml tag. Preview is visible https://ibb.co/9VjDzc1 – waheed shah Aug 26 '21 at 09:59
  • I don't think "ignore this preview error" is a good alternative. – m0skit0 Aug 26 '21 at 14:21
  • If I ignore this preview how would I adjust the layout according to design? – waheed shah Aug 27 '21 at 04:27
  • hi@waheed shah, Could you try to change NativeView to RelativeLayout, adjust it and then change it back? – zhangxaochen Aug 27 '21 at 06:23
  • And thank you for providing the information regarding this issue. The R&D team confirms that this issue will be fixed in the next version. – zhangxaochen Aug 27 '21 at 06:46
  • 1
    hi @shirley currently I m changing views to adjust according to design. Waiting for the fix. Thanks for your immediate response. – waheed shah Aug 27 '21 at 07:23