Android Tutorial AndroidX SDK

Status
Not open for further replies.
Android Support Library was implemented and maintained in the last 8 years by Google. It includes a wide range of features and it hides many of the differences between the various Android versions.

Android Support Library was replaced by AndroidX SDK. It is no longer maintained and new versions of Firebase SDK depend on AndroidX. This is a good time to switch to AndroidX.

It is simple to switch to AndroidX as the IDE takes care of most of the things:

- Libraries references (DependsOn / #AdditionalJar) are updated automatically.
- The compiler automatically chooses the androidx libraries if such are available.
- References to support classes in #Extends declarations, JavaObject calls and to a less extent in the manifest editor code are converted during compilation.

Most of the libraries will work as-is, however libraries that directly call methods from the support library need to be "jetified". This is done with the Jetifier tool (Tools - Jetifier). It will go over all the additional libraries and will jetify all the libraries that need to be jetified. The output of this tool is libraries with .androidx.jar (or .androidx.aar) extension.
The B4A compiler will then use those libraries automatically.

Note that the internal libraries already include the jetified versions.

To conclude:

1. Open Tools - B4A Sdk manager.
2. Install all recommended items. This will make the switch to AndroidX. You can always go back to the previous SDK.
3. Open Tools - Jetifier.
4. Click on Jetify. It is possible that the jetifier will fail to jetify a few libraries. In most cases you can ignore it as those libraries don't need to be jetified.
5. Clean the project (Ctrl + P)
6. Run your project. The compilation dialog will tell you which SDK was used:

B4A Version: 9.30 BETA #2
Java Version: 11
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.02s)
Compiling layouts code. (0.01s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. (0.96s)
Compiling debugger engine code. (0.73s)
Compiling generated Java code. (1.36s)
Convert byte code - optimized dex. (1.06s)
Packaging files. (0.83s)
Copying libraries resources (0.01s)
Signing package file (private key). (0.61s)
ZipAlign file. (0.04s)
Installing file to device. (0.03s)
Installing with B4A-Bridge.
Completed successfully.
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hello Erel,
Firstly just 1001 to go (at time of this post) ;)
Would it be okay for me to manually delete the original .jar or .aar once they have been jetified (as long as there is an .androidx. file that matches), I presume that it's 100% fine to do that.

Thank you...
 
Last edited:

fbritop

Active Member
Licensed User
Longtime User
B4X:
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.00s)
Compiling generated Java code.    Error
B4A line: 796
Dim s As ACSwitch = Sender
javac 1.8.0_91
src\cl\abreme\android\aacceso.java:420: error: package android.support.v7.widget does not exist
_s.setObject((android.support.v7.widget.SwitchCompat)(anywheresoftware.b4a.keywords.Common.Sender(mostCurrent.activityBA)));
Do we have to use AndroidX for AppCompat?
 

Peter Simpson

Expert
Licensed User
Longtime User
B4X:
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.00s)
Compiling generated Java code.    Error
B4A line: 796
Dim s As ACSwitch = Sender
javac 1.8.0_91
src\cl\abreme\android\aacceso.java:420: error: package android.support.v7.widget does not exist
_s.setObject((android.support.v7.widget.SwitchCompat)(anywheresoftware.b4a.keywords.Common.Sender(mostCurrent.activityBA)));
Do we have to use AndroidX for AppCompat?

What was your previous version of B4A?
 

fbritop

Active Member
Licensed User
Longtime User
Was not added @Peter Simpson , after adding the missing SDK (Which was not installed) I have the same error. Do I need to change the @Extends too?, if so to which directive?

B4X:
#Extends: android.support.v7.app.AppCompatActivity
 

Attachments

  • upload_2019-7-1_13-45-1.png
    upload_2019-7-1_13-45-1.png
    11.4 KB · Views: 1,282

Graeme Tacon

Member
Licensed User
Longtime User
I've followed the above, but I'm getting the following when I try and compile my app:

B4A Version: 9.30 BETA #2
Java Version: 8
Parsing code. (0.22s)
Building folders structure. (1.30s)
Compiling code. (0.49s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.05s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex
 

DonManfred

Expert
Licensed User
Longtime User

sorex

Expert
Licensed User
Longtime User
Erel,

You mentioned somewhere that the Firebase things will be based on this new AndroidX SDK.

Does this mean that there will be new FirebaseAdmob libs coming? or are we still safe for a while?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Was not added @Peter Simpson , after adding the missing SDK (Which was not installed) I have the same error. Do I need to change the @Extends too?, if so to which directive?
Please start a new thread. You don't need to change the #Extends class.

You mentioned somewhere that the Firebase things will be based on this new AndroidX SDK.
B4A Firebase libraries depend on Firebase SDK. B4A Firebase libraries will work with the current version of Firebase SDK as well as older versions.
The latest version of Firebase SDK depends on AndroidX SDK. I hope that it is clear...
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hi,
can you explain to me what the Android Support Library is about and the AndroidX SDK difference?

Thank in advance
regards
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Roberto P.

Well-Known Member
Licensed User
Longtime User
The main motivation behind these libraries is to allow Android to evolve without relying on OS updates. AndroidX replaces the now deprecated Support Library.[/QUOTE said:
thank you Erel
 

drgottjr

Expert
Licensed User
Longtime User
I don't seem to have a Jetifier. Not sure what I failed to do.
Started Sdk Manager (it goes for https://dl.google.com/dl/android/maven2/master-index.xml). reported nothing to install.
I also downloaded the latest tools (sdk-tools-windows-4333796.zip) and installed as usual. (c:\android\tools)

No Jetifier under IDE tools

1) SDK Manager version 3.34
2) B4A 9.01.2
3) C:\Android\platforms\android-28\android.jar (set in Paths)
4) C:\Program Files\Java\jdk1.8.0_211\bin\javac.exe (set in Paths)
5) Have been building my projects without incident, so, presumably, everything that was needed was in place.
 

drgottjr

Expert
Licensed User
Longtime User
Status
Not open for further replies.
Top