With the release of Android Studio 3.6, there are new features that will get you excited, and M is happy to click the “Check for Updates” button to install Android Studio and start his new adventure.



① Many “encounters”

“Gee, what did Google update? I hear a lot of things are being optimized, but I can’t think of them off the top of my head, and it would be a shame to miss some features.” With this in mind, He opened his newly updated Android Studio:

What’s New in 3.6 wow, isn’t that What Little M wants? Take a quick look. Android Gradle plugin 3.6.0 Updates /Emulators/… And so on. The Assistant is kind of fun. The embedded WebView-like information display experience left a very good impression on M.


② It was a good conversation

Today, M received an assignment to connect the Google Firebase component to an App developed by the company for overseas users. Firebase provides a lot of functionality with Google Play Services, so isn’t it complicated to access so much content? Some domestic companies provide a single business SDK all by distributing Gradle coordinate dependency to provide user access, Firebase will not be the same way?

M opened the official website of Android Developer to check how to access the Firebase SDK, found the following content:

Ha! Ha! Assistant again, is it the same thing? Following the instructions above, M opens the Assistant provided by Firebase:

Wow, this is much richer than What’s New, with links to click on. Each section is a different component. After clicking on a component, we can see the following tutorial:

The interaction is much richer, not only with buttons, but also with code snippets. The structure of Step 1/2/3/4 is so clear that it’s almost like Google is teaching you how to access Firebase, and the experience is much more comfortable than looking at a dry document. The first step is to log in to your Google account in Android Studio and click “Connect to Firebase”. After selecting the project, we found that our App project now has google-services.json, which we had to manually access

Looking back at Assistant, the first step is complete:

Wow, so I don’t have to check myself, so continue to click the second step, and a dialog box appears:

This tells us what will happen to our project if we apply the Changes. After clicking “Accept Changes”, we can look at build.gradle and see that it has already been applied:

Plugin: 'com.google.gms.google-services' android {// Apply plugin: 'com.google.gms.google-services' Android {... } dependencies {implementation 'com. Google. Firebase: firebase - auth: 19.3.0'}Copy the code

In this way, we want to access the Auth component is complete, directly run run good.

Isn’t this way of accessing too comfortable?


3. Say Hi

M received a task today. The company has an SDK that needs to be exported to the Internet. M remembered the Assistant tool again. Therefore, Xiao M began to investigate how to develop an Assistant interface using the development method of IDEA Plugin.

First, the IDEA of the Plugin development environment (https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html) is configured according to the document, Since the Assistant mechanism is provided by Android Studio, support for the Android Plugin needs to be added during the development process, namely in the Intellij DSL:

intellij { //..... omitsetPlugins("java"."gradle"."groovy"."terminal"."android")}Copy the code

After the addition, we will have all the environment for Android Studio plug-in Development. At the same time, we should be prepared, because the environment for IDEA plug-in Development is relatively bad, and there is no other detailed information for reference except the Plugin Development Guide provided by the official. For Assistant related development, you can only refer to the relevant source code.

So we refer to two source code, one is the decomcompiled Firebase Plugin source code, the other is the source code inside Android Studio to achieve, we first look at the decomcompiled Firebase Plugin source code, After decomcompiling the Firebase Plugin JAR package, we can find the information described in the Assistant interface simply by looking up the keywords in the jar. For example, Firebase gives you the tools and infrastructure from Google to help you develop, Grow and earn money from your app”



Immediately it becomes clear that our Assistant interface is actually generated by Android Studio’s analysis of this XML-generating UI component — since IDEA is built by Swing, Swing UI does not provide a WebView, We can’t get the capabilities of a native WebView.

We can search firebase_tutorial_bundle.xml again to see where this XML is used.



Further up, the class is registered in plugin.xml

<idea-plugin> <! -- omit unimportant nodes --> < Extensions defaultExtensionNs="com.android.tools.idea.assistant">
    <assistantBundleCreator implementation="com.google.services.firebase.FirebaseBundleCreator"/>
    <actionStateManager implementation="com.google.services.firebase.DependencyStateManager"/>
    <actionHandler implementation="com.google.services.firebase.AddDependencyAction"/>
    <actionStateManager implementation="com.google.services.firebase.FirebaseConnectStateManager"/>
    <actionHandler implementation="com.google.services.firebase.FirebaseConnectAction"/>
    <actionHandler implementation="com.google.services.firebase.RecordRoboScriptAction"/>
  </extensions>

  <actions>
    <action
        id="DeveloperServices.Firebase"
        class="com.google.services.firebase.FirebaseOpenSidePanel"
        text="Firebase"
        description="Add Firebase to your app">
      <add-to-group group-id="AndroidToolsGroupExtension"/>
    </action>
  </actions>
</idea-plugin>Copy the code

FirebaseBundleCreator has one line of code in it:

public class FirebaseBundleCreator implements AssistantBundleCreator {
    private static final String TUTORIAL_CONFIG_FILENAME = "/firebase_tutorial_bundle.xml";
	
    @NotNull
    public String getBundleId() {
        return "DeveloperServices.Firebase"; }}Copy the code

The BundleId corresponds to the Id of the FirebaseOpenSidePanel action, so that the action is associated with the bundle.

After copying these classes, “Hello World” is complete.




④ Deployment Tutorial

We’ll look back firebase_tutorial_bundle. There is a feature of XML/description/tutorial/step nodes, such as different nodes have different representations, after we fill the copy, There is a complete interface that can contain steps. If you want to see what other nodes can be used, we can see the com. Android. View idea. Assistant. DefaultTutorialBundle this class, after we fill the copy well, has been a complete interface can contain steps.



Small M made use of the Assistant provided by Android Studio to quickly develop the access scheme of mPaaS Android, which has been released to the public. This is our latest attempt to fast access to public cloud. Hopefully, the SDKS provided by mPaaS will more and more meet the appetite of all developers, and the capabilities provided by mPaaS will better serve all mobile developers.



——END——