Android Question for #AdditionalJar question

jstzjjk

Member
I searched all the forum, i can not found a complete,detailed useage about #AdditionalJar,
such as #AdditionalJar: com.android.support:appcompat-v7
what means of the first param,and the second param? what is the working mechanism? who can tell me?
I can only poorly guess it?
 

aeric

Expert
Licensed User
Longtime User
#AdditionalJar: com.android.support:appcompat-v7
This is self explanatory.
Additional = you need to add this extra file
Jar = Java archived format file
This is used when your project requires extra supporting library where this library does not need to be wrapped. You can download it from the Internet and use it as it is.
Other example like:
B4X:
#AdditionalJar: com.google.android.gms:play-services-vision

Just find, download and save this file to your additional folder then reference it using that #AdditionalJar keyword.

Edit: Some additional jar libraries are obtained by running the SDK Manager.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/threads/appcompat-with-toolbar-minimal-example.79896/#content
In most cases AppCompat is no longer needed and will only make things more complicated.

And if you want to use AppCompat, can use keyword #Extends.
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
    #Extends: android.support.v7.app.AppCompatActivity
    #IgnoreWarnings: 32
#End Region

Here is the documentation for AdditionalJar.
 
Last edited:
Upvote 0

jstzjjk

Member
I know it use for additional jar. I have read this thread many times.
i am not for com.android.support:appcompat-v7 ,
but I need know how to use #AdditionalJar, where its gramma?
before colon and after colon, what means?

example:
#AdditonalJar: c:\test.aar:com.aa.bb
such as #AdditonalJar c:\test.aar, i know it will unpacked c:\test.aar,and use it.
what means com.aa.bb ?

#AdditionalJar: com.google.android.gms:play-services-vision
is it means use the file com.google.android.gms.aar in default directory ? then what means play-services-vision ?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
It is just a compiler directive to tell the compiler that your code will use the third party library. You don’t need to understand deeply as every tutorial will ask you to add that line if it is required. The example I showed about play-services-vision is for QR code scanner with camera where the SDK is provided by Google. However, you can also compile your own Java library using Eclipse or IntelliJ IDEA and use this #AdditionalJar to load the jar library as show in the tutorial. Otherwise you can use inline Java code. JavaObject is useful to call the Java methods in both scenarios.
 
Upvote 0

jstzjjk

Member
at here https://www.b4x.com/android/forum/threads/addtionalres-additionaljar-b4a-6.67802/
it saids
(1)#AdditionalRes: F:\Android\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
is equal to
#AdditionalJar: com.google.android.gms:play-services-location

(2) #AdditionalRes: F:\Android\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
is equal to
#AdditionalJar: com.android.support:appcompat-v7

for (2) ,it seems to there is an aar file, which can unziped, the sub directory is android\support\v7\appcompat\*
is it means (1) res is F:\Android\extras\android\support\v7\appcompat\res, jar is F:\Android\extras\android\support\v7\appcompat\class.jar
but while write as #AdditionalJar: com.android.support:appcompat-v7,what means :appcompat-v7?

for(1),it seems that unziped path is google\google_play_services\libproject\google-play-services_lib
...
i can not understand which is before colon and after colon
 
Upvote 0

jstzjjk

Member
It is just a compiler directive to tell the compiler that your code will use the third party library. You don’t need to understand deeply as every tutorial will ask you to add that line if it is required. The example I showed about play-services-vision is for QR code scanner with camera where the SDK is provided by Google. However, you can also compile your own Java library using Eclipse or IntelliJ IDEA and use this #AdditionalJar to load the jar library as show in the tutorial. Otherwise you can use inline Java code. JavaObject is useful to call the Java methods in both scenarios.
you means just know copy it then ok? don't neek know its gramma?
but now my project compile appears many errors about res, how can i sove it?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
#AdditonalJar: c:\test.aar:com.aa.bb
You should put the xxx.jar file in Additional library folder only. B4A will automatically find the library and add it during compilation.

I think the structure is
#AdditionalJar: namespace:library:version

I never concern about this line as when we develop with B4X, we just follow Erel’s and other members’ tutorial. This line is just a way to import dependencies for that project.
Sometimes we also need to add extra code or declarations in manifest editor. Just pay attention to the instructions will do.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
you means just know copy it then ok? don't neek know its gramma?
but now my project compile appears many errors about res, how can i sove it?
It is better to show your project code. If you don’t need the appcompat library then just remove it. Please also post the sample project you copy the project from.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Upvote 0

jstzjjk

Member
my conclusion:
in AS, implementation namespace:library:version, the really aar is library-version.aar
implementation 'androidx.appcompat:appcompat:1.1.0'-------->appcompa-1.1.0.aar

#AdditionalJar: path of aar, ReferenceOnly

about #AdditionalJar:
 'in sdk\extra directorys
' F:\___sdk___\extras
'        android
'        b4a_local--->addition_library_unpack_here.
'        b4a_remote
'        goolge
'        intel
'        m2repository
'path is [F:\___sdk___\extras\b4a_remote]\androidx\appcompat\appcompat\1.4.2\appcompat-1.4.2.aar
' androidx/appcomat:appcompat/version/appcompat-version.aar
' how to express version ,comma, or auto?
#AdditionalJar: androidx.appcompat:appcompat
'path is [F:\___sdk___\extras\android\m2repository]\com\android\support\appcompat-v7\22.1.0\appcompat-v7-22.1.0.aar
#AdditionalJar: com.android.support:appcompat-v7
'path is C:\_FetchDemo\jar_aar\okhttp-4.9.2.jar
#AdditionalJar:C:\_FetchDemo\jar_aar\okhttp-4.9.2.jar
'And I found #AdditionalJar: yourjar, ReferenceOnly
'ReferenceOnly just Like Gradle Dependencies compileOnly?
#AdditionalJar: gson.aar, ReferenceOnly
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don't know why you want to make things complicated.
B4A makes things easier compared to AS.

If you want to use AppCompat, add the #Extends and reference the library in Library tab.
If you want to use OkHttp, there is library you can check in Library tab too. I recommend you to use OkHttpUtils2 which is bundled with B4A by default as internal library.

If you have error in you project, post your sample project and errors in text.
 
Upvote 0
Top