background

I’ve been following up on JetPack recently, and I’ve noticed that the names of many dependencies have changed a bit since I switched from support to androidx. Every time I want to add a dependency, I have to check the website to see the path and version. But in the world of jetbrains plug-in, have a completion of the plug-in automatically GradleDependenciesHelperPlugin, it only supports from mavenCentral search does not support Google () () in the warehouse, That’s where android-Dependencies – Completion comes in, an attempt to be friendly to Android development with dependencies.

features

  • Support for gradle dependent library name auto-completion, includingJetpackRelated software packages
  • Support version number extract build variable and entire path extract build variable
  • The variable extraction function can be used separately
  • A clear and concise user interface

How to get

AS installed in

Search Android Studio->Setting ->Plugins for the keyword android-dependencies-completion or 12479:

The jar packages installed

Plug-in website: plugins.jetbrains.com/plugin/1247…

Download at github.com/HitenDev/an…

You can download the JAR package from the above two addresses. The method of installing the local JAR plug-in AS is relatively simple, so there is no longer any trouble here.

How to use

Master shortcut keys

The plug-in depends on Code Completion->SmartType Completion. Therefore, ensure that SmartType Completion is enabled and that the shortcut keys for wrapping SmartType Completion do not conflict with other shortcut keys.

Default shortcut keys:

  • MacOS ^(control) + registering (shift) + space
  • Windows ctrl + alt + space
  • Linux ctrl + shift + space

It is reported that the Windows shortcut key and the system shortcut key conflict, please use the friends of patience to solve the conflict, do not give up because of this;

The basic use

When entering a string in your project Gradle file, press the shortcut key if you need to complete it

There are no restrictions on build.gradle, no restrictions on dependencies, no restrictions on implementation or compile;

In general, android developers like to place their dependent libraries in the same place, not necessarily defined in build.gradle. All of these scenarios need to be supported.

Generate variable

Android developers are used to extracting Gradle dependencies as variables. This scenario is also taken into account by adding a # symbol at the end of the input string.

  • Add a#, indicating that the version number needs to be extracted
  • Add two# #, which means that the entire string needs to be extracted;

Common scenarios:

Because dependency library strings are composed of three groups :artifact: Version components, and most users will not enter keywords in complete triplets, # support completion in a missing state;

  • The keyword + #

  • group:artifact:+#

Go directly

  • group:artifact:version+#When the string is added by the complete format#, the variable is extracted directly and the replacement is completed

Variable rules

Naming rules

  • use#The generated version variable, named ver_$artifact
//before
implementation 'com. Google. Code. Gson: gson: 2.8.5 #'

//after
ext.ver_gson = '2.8.5' //please move this code to a unified place.
implementation "com.google.code.gson:gson:$ver_gson"
Copy the code
  • #If the string XXX is appended to the number, the name is ver_xxx
//before
implementation 'com. Google. Code. Gson: gson: 2.8.5 # hiten'

//after
ext.ver_hiten = '2.8.5' //please move this code to a unified place.
implementation "com.google.code.gson:gson:$ver_hiten"
Copy the code
  • use# #The generated full path variable, named dep_$artifact
//before
implementation 'com. Google. Code. Gson: gson: 2.8.5 # #'

//after
ext.dep_gson = 'com. Google. Code. Gson: gson: 2.8.5' //please move this code to a unified place.
implementation "$dep_gson"
Copy the code
  • # #If the string XXX is appended to the number, the name is dep_xxx
//before
implementation 'com. Google. Code. Gson: gson: 2.8.5 # # hiten'

//after
ext.dep_hiten = 'com. Google. Code. Gson: gson: 2.8.5' //please move this code to a unified place.
implementation "$dep_hiten"
Copy the code

Insert the rules

The code generated by the variable will be inserted one line above the current cursor and left-aligned with the current line. Theoretically, this line of code is not important to put here, so the author usually needs to move this line of code to the specified position in the project;

ext.ver_gson = '2.8.5' //please move this code to a unified place.
Copy the code

other

Single/double quotation marks are not limited

You can use a $reference variable in a gralde string if the string is enclosed in double quotes. I’ve done a special conversion here, so the user doesn’t care whether it’s in single or double quotes, just use # to generate it;

Again: Auto-complete does not trigger automatically, it needs to be triggered by a shortcut key, please do not confuse the reader.

Focus on the project

If you are interested in this feature, you can add it to improve:

Project address: github.com/HitenDev/an…

If you have new ideas, please chat with me privately or add Issues on Github.

To contact me

  • nickname: HitenDev
  • email: [email protected]
  • gayhub : github.com/HitenDev
  • The Denver nuggets: Juejin. Cn/user / 437131…