Java Question Problem in Android Studio to Wrap libraries

Salar82

Member
Hi All.
In this tutorial https://www.b4x.com/android/forum/threads/create-a-wrapper-library-with-android-studio.82831/ , I became somewhat familiar with how to create a library with Android Studio and did all the steps. But I have the following problems:

1) In build.gradle, the following two lines encounter an error:

B4X:
enforceUniquePackageName = false
android.packageBuildConfig = false

error:
Could not set unknown property 'enforceUniquePackageName' for extension 'android' of type com.android.build.gradle.LibraryExtension.

By deleting these two lines, the library will be well compiled But after run project, I face another problem:
2) The xml file is created without an extension.


Annotation 2020-07-21 005358.png


3) I write the extension for xml file and pass it to the Additional library.
In B4A, I run the project, but I also encounter a new error when compiling:

B4X:
B4A Version: 10.0
Java Version: 8
Parsing code.    (0.00s)
Building folders structure.    (0.12s)
Compiling code.    (0.03s)
Compiling layouts code.    (0.06s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (7.87s)
Compiling debugger engine code.    (0.04s)
Compiling generated Java code.    Error
javac 1.8.0_74
error: error reading E:\B4A\AdditionalLibrary\imagesliderlibrary.jar; error in opening zip file
1 error


If I could not speak English well, I'm sorry because my English is not good.šŸ„“
I hope the problems will be solved with your guidance
 
Last edited:

Salar82

Member
I noticed an interesting problem:
File ImageSliderlibrary.jar in Build folder is empty:

Annotation 2020-07-21 173631.png
Annotation 2020-07-21 173855.png


And build.gradle
Java:
apply plugin: 'com.android.library'

android {
//    repositories {
//        // The order in which you list these repositories matter.
//        google()
//        jcenter()
//    }
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
//    enforceUniquePackageName = false
//    android.packageBuildConfig = false



    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    task copyB4AFiles(type: Copy, dependsOn: "assembleRelease") {
        from 'src/ImageSliderLibrary.jar'
        from 'build/outputs/aar/ImageSliderLibrary-release.aar'
        into 'build/B4Alibs'
        rename { String fileName ->
            fileName.replace('-release', '')
        }
    }
}


dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
//    implementation files('libs/core.jar')
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation project(path: ':ImageSlider-jar')
    implementation project(path: ':B4AShared')
    implementation project(path: ':Core')
    implementation project(path: ':glide-3.6.0')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}
 

Salar82

Member
now I can fix all problems:

1) In build.gradle, the following two lines encounter an error:
I delete these lines And fix error

2) The xml file is created without an extension.

rebuild configuration

3) I write the extension for xml file and pass it to the Additional library.
In B4A, I run the project, but I also encounter a new error when compiling:
The problem was that I renamed a file .txt to .jar.
I need to rename a file .zip

File ImageSliderlibrary.jar in Build folder is empty:
According to @corwin42 , it should be like this.

I Created library with SLC And Android Studio; But In both cases, I get the following error when running Wrapped Library on B4A:

B4X:
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/AccessibilityDelegateCompat;
    at com.smarteist.autoimageslider.SliderView.setupSlideView(SliderView.java:187)
    at com.smarteist.autoimageslider.SliderView.<init>(SliderView.java:80)
    at ir.imageslider.ash.ShImageSlider.Initialize(ShImageSlider.java:25)
    at b4a.example.main._activity_create(main.java:388)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.AccessibilityDelegateCompat" on path: DexPathList[[zip file "/data/app/b4a.example-2/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-2/lib/x86, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 20 more
** Activity (main) Resume **

this is SliderViewWrapper Class:
B4X:
package ir.imageslider.ash;

import android.view.ViewGroup;
import com.smarteist.autoimageslider.SliderView;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.keywords.Common.DesignerCustomView;
import anywheresoftware.b4a.objects.LabelWrapper;
import anywheresoftware.b4a.objects.PanelWrapper;
import anywheresoftware.b4a.objects.ViewWrapper;

@ShortName("ShImageSlider")
@Version(1.0f)
@Author("A.Sh")
@DependsOn(values = {"autoimageslider-1.3.9.aar", "glide-3.6.0.jar", "ShImageSlider.aar"})
public class ShImageSlider extends ViewWrapper<SliderView> implements DesignerCustomView {
    private BA ba;
    private SliderView sv;

    public void Initialize(BA ba, String EventName) {
        _initialize(ba, null, EventName);
        sv = new SliderView(ba.context);
    }

    @Hide
    public void _initialize(BA ba, Object activityClass, String EventName) {
        this.ba = ba;
    }

    public void DesignerCreateView(PanelWrapper base, LabelWrapper lw, anywheresoftware.b4a.objects.collections.Map props) {
        ViewGroup vg = (ViewGroup) base.getObject().getParent();
        AddToParent(vg, base.getLeft(), base.getTop(), base.getWidth(), base.getHeight());
        sv = new SliderView(ba.context);
        base.RemoveView();
    }

    @Hide
    public void AddToParent(ViewGroup Parent, @Pixel int left, @Pixel int top, @Pixel int width, @Pixel int height) {
        Parent.addView(sv, new BALayout.LayoutParams(left, top, width, height));
    }

    public void setLeft(int left) {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        lp.left = left;
        sv.getParent().requestLayout();
    }

    public int getLeft() {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        return lp.left;
    }

    public void setTop(int top) {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        lp.top = top;
        sv.getParent().requestLayout();
    }

    public int getTop() {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        return lp.top;
    }

    public void setWidth(int Width) {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        lp.width = Width;
        sv.getParent().requestLayout();
    }

    public int getWidth() {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        return lp.width;
    }

    public void setHeight(int height) {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        lp.height = height;
        sv.getParent().requestLayout();
    }

    public int getHeight() {
        BALayout.LayoutParams lp = (BALayout.LayoutParams) sv.getLayoutParams();
        return lp.height;
    }
}

And SliderView Class:
B4X:
public class SliderView extends FrameLayout implements Runnable, OnTouchListener, DataSetListener, OnPageChangeListener {


    public SliderView(Context context) {
        super(context);
        this.setupSlideView(context);
    }

    public SliderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setupSlideView(context);
        this.setUpAttributes(context, attrs);
    }

    public SliderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.setupSlideView(context);
        this.setUpAttributes(context, attrs);
    }
 
Last edited:
Top