Android Tutorial AndroidX SDK

Discussion in 'Tutorials & Examples' started by Erel, Jul 1, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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: Jul 2, 2019
  2. Peter Simpson

    Peter Simpson Expert Licensed 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: Jul 1, 2019
  3. Erel

    Erel Administrator Staff Member Licensed User

    In the current beta you will get a warning when you open the project if there is no jar file with the same name. I will fix it.
    Note that most libraries will not produce an androidx lib.
     
  4. Peter Simpson

    Peter Simpson Expert Licensed User

    Thank you Erel...
     
  5. fbritop

    fbritop Active Member Licensed User

    Code:
    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?
     
  6. Peter Simpson

    Peter Simpson Expert Licensed User

    What was your previous version of B4A?
     
  7. fbritop

    fbritop Active Member Licensed User

  8. fbritop

    fbritop Active Member Licensed 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?

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

    Attached Files:

  9. Graeme Tacon

    Graeme Tacon Member Licensed 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
     
  10. DonManfred

    DonManfred Expert Licensed User

    1. See the installation instructions here: https://www.b4x.com/b4a.html#installation
    2. Make sure to configure the ide to use the new SDK
    3. Make sure you select the android.jar from platform 28.
     
    Shelby, Peter Simpson and Erel like this.
  11. Graeme Tacon

    Graeme Tacon Member Licensed User

    Shelby likes this.
  12. sorex

    sorex Expert Licensed 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?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread. You don't need to change the #Extends class.

    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...
     
  14. Roberto P.

    Roberto P. Well-Known Member Licensed User

    Hi,
    can you explain to me what the Android Support Library is about and the AndroidX SDK difference?

    Thank in advance
    regards
     
  15. LucaMs

    LucaMs Expert Licensed User

    Very good question but I think we should inform ourselves well about this on the official Google site.
    We cannot pretend Erel to explain to us everything that is inside Android.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

  17. Roberto P.

    Roberto P. Well-Known Member Licensed User

     
  18. drgottjr

    drgottjr Active Member Licensed 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.
     
  19. asales

    asales Well-Known Member Licensed User

  20. drgottjr

    drgottjr Active Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice