Update App Indexing Code Generation Functionality

App Indexing API is updated to v2, so we have to update codes generated for
App Indexing.

Foturnately, new API has less dependencies, which make codes simpler.

This change follows https://firebase.google.com/docs/app-indexing/android/migrate
to migrate codes to new API.

This change also removes denpendencies adding functionality,
because new App Indexing API is part of Firebase SDK, we can add api
dependencies through "Add Dependency" action in Firebase Assistant.
cl/140329785 will make it happen.

To run this code in your local Studio, please follow:
1. cherry pick this CL and then cherry pick ag/1676966
2. open firebase assistant and click through
"App Indexing"-> "Get Started with App Indexing"
3. Click button in Step 2 to add App Indexing dependency into your test
app module.
4. Click right button of your mice to trigger popup menu
5. Click "Generating" -> "App Indexing Code" in activity source file to
see generated code.

Test: Add new test cases, update some existing test cases with new
generated content, and remove unused test cases.

Change-Id: I066e4a3867a0a093c2242b0c632620d6ba8e1c27
(cherry picked from commit 4de8ae5346ffa19d91f02b72a5d3a923c9ce9ec7)
diff --git a/BUILD b/BUILD
index ac9326b..d3ca847 100644
--- a/BUILD
+++ b/BUILD
@@ -35,5 +35,6 @@
         "//tools/idea/.idea/libraries:mockito[test]",
         "//tools/analytics-library/protos:analytics-protos[module]",
         "//tools/analytics-library/tracker:analytics-tracker[module]",
+        "//tools/adt/idea/android-plugin[module]",
     ],
 )
diff --git a/google-appindexing.iml b/google-appindexing.iml
index fa432b9..e45951e 100644
--- a/google-appindexing.iml
+++ b/google-appindexing.iml
@@ -43,5 +43,6 @@
     <orderEntry type="library" scope="TEST" name="mockito" level="project" />
     <orderEntry type="module" module-name="analytics-protos" />
     <orderEntry type="module" module-name="analytics-tracker" />
+    <orderEntry type="module" module-name="android-plugin" />
   </component>
 </module>
\ No newline at end of file
diff --git a/src/com/google/appindexing/api/ApiCreator.java b/src/com/google/appindexing/api/ApiCreator.java
index 2412799..95490f3 100644
--- a/src/com/google/appindexing/api/ApiCreator.java
+++ b/src/com/google/appindexing/api/ApiCreator.java
@@ -17,105 +17,79 @@
 
 import com.android.SdkConstants;
 import com.android.annotations.VisibleForTesting;
-import com.android.builder.model.AndroidArtifact;
-import com.android.builder.model.AndroidLibrary;
-import com.android.builder.model.Dependencies;
-import com.android.builder.model.MavenCoordinates;
-import com.android.ide.common.repository.GradleCoordinate;
-import com.android.tools.idea.gradle.project.model.AndroidModuleModel;
 import com.android.tools.idea.gradle.dsl.model.GradleBuildModel;
 import com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel;
 import com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec;
+import com.android.tools.idea.gradle.dsl.model.dependencies.CommonConfigurationNames;
 import com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel;
-import com.android.tools.idea.gradle.project.sync.GradleSyncInvoker;
 import com.google.appindexing.util.DeepLinkUtils;
 import com.google.appindexing.util.ManifestUtils;
-import com.google.common.base.CharMatcher;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.intellij.ide.highlighter.JavaFileType;
 import com.intellij.lang.java.JavaLanguage;
-import com.intellij.lang.xml.XMLLanguage;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleUtilCore;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
 import com.intellij.psi.codeStyle.CodeStyleManager;
 import com.intellij.psi.codeStyle.JavaCodeStyleManager;
-import com.intellij.psi.codeStyle.VariableKind;
 import com.intellij.psi.util.InheritanceUtil;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.psi.xml.XmlComment;
 import com.intellij.psi.xml.XmlFile;
 import com.intellij.psi.xml.XmlTag;
+import com.intellij.util.text.VersionComparatorUtil;
 import com.siyeh.ig.psiutils.ImportUtils;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import static com.android.tools.idea.gradle.dsl.model.dependencies.CommonConfigurationNames.COMPILE;
-import static com.android.tools.idea.gradle.util.GradleUtil.getDependencies;
+import static com.android.tools.idea.gradle.dsl.model.values.GradleValue.getValues;
 
 /**
  * A class for detecting the situation where developers need App Indexing API code and inserting
  * the API code in their projects.
  */
 public final class ApiCreator {
-  static private final String COMPILE_GMS_GROUP = "com.google.android.gms";
-  static private final String COMPILE_APPINDEXING = "play-services-appindexing";
-  static private final String MINIMUM_VERSION = "8.4.0";
 
-  static private final String TAG_METADATA = "meta-data";
-  static private final String ATTR_NAME_METADATA_GMS = "com.google.android.gms.version";
-  static private final String ATTR_VALUE_METADATA_GMS = "@integer/google_play_services_version";
 
   static private final String METHOD_GET_ACTION = "getIndexApiAction";
 
   static private final String CLASS_ACTION = "Action";
-  static private final String CLASS_APP_INDEX = "AppIndex";
-  static private final String CLASS_GOOGLE_API_CLIENT = "GoogleApiClient";
-  static private final String CLASS_THING = "Thing";
-  static private final String CLASS_ACTION_FULL = "com.google.android.gms.appindexing.Action";
-  static private final String CLASS_APP_INDEX_FULL = "com.google.android.gms.appindexing.AppIndex";
-  static private final String CLASS_THING_FULL = "com.google.android.gms.appindexing.Thing";
-  static private final String CLASS_GOOGLE_API_CLIENT_FULL = "com.google.android.gms.common.api.GoogleApiClient";
+  static private final String CLASS_FIREBASE_USER_ACTION = "FirebaseUserActions";
+  static private final String CLASS_BUILDERS_ACTIONS = "Actions";
 
-  static private final List<String> SIGNATURE_ON_CREATE = Lists.newArrayList("android.os.Bundle");
+
+  static private final String CLASS_ACTION_FULL = "com.google.firebase.appindexing.Action";
+  static private final String CLASS_FIREBASE_USER_ACTION_FULL = "com.google.firebase.appindexing.FirebaseUserActions";
+  static private final String CLASS_BUILDERS_ACTIONS_FULL = "com.google.firebase.appindexing.builders.Actions";
+
+
+
   static private final List<String> SIGNATURE_ON_START = Lists.newArrayList();
   static private final List<String> SIGNATURE_ON_STOP = Lists.newArrayList();
-  static private final String ON_CREATE_FORMAT = "@Override\n" +
-                                                 "protected void onCreate(android.os.Bundle savedInstanceState) {\n" +
-                                                 "  super.onCreate(savedInstanceState);\n" +
-                                                 "  \n" +
-                                                 "  // ATTENTION: This was auto-generated to implement the App Indexing API.\n" +
-                                                 "  // See https://g.co/AppIndexing/AndroidStudio for more information.\n" +
-                                                 "  %1$s = new %2$s.Builder(this).addApi(%3$s.API).build();\n" +
-                                                 "}";
   static private final String ON_START_FORMAT = "@Override\n" +
                                                 "public void onStart(){\n" +
                                                 "  super.onStart();\n" +
                                                 "  \n" +
                                                 "  // ATTENTION: This was auto-generated to implement the App Indexing API.\n" +
                                                 "  // See https://g.co/AppIndexing/AndroidStudio for more information.\n" +
-                                                "  %1$s.connect();\n" +
-                                                "  %3$s.AppIndexApi.start(%1$s, %2$s);\n" +
+                                                "  %1$s.getInstance().start(%2$s());\n" +
                                                 "}";
   static private final String ON_STOP_FORMAT = "@Override\n" +
                                                "public void onStop() {\n" +
-                                               "  super.onStop();\n" +
                                                "  \n" +
                                                "  // ATTENTION: This was auto-generated to implement the App Indexing API.\n" +
                                                "  // See https://g.co/AppIndexing/AndroidStudio for more information.\n" +
-                                               "  %3$s.AppIndexApi.end(%1$s, %2$s);\n" +
-                                               "  %1$s.disconnect();\n" +
+                                               "  %1$s.getInstance().end(%2$s());\n" +
+                                               "  super.onStop();\n" +
                                                "}";
 
   static private final String GET_ACTION_FORMAT = "/**\n" +
@@ -123,43 +97,28 @@
                                                   " * See https://g.co/AppIndexing/AndroidStudio for more information.\n" +
                                                   " */\n" +
                                                   "public %4$s %1$s() {\n" +
-                                                  "  %5$s object = new %5$s.Builder()\n" +
-                                                  "      .setName(\"%2$s Page\") // TODO: Define a title for the content shown.\n" +
-                                                  "      // TODO: Make sure this auto-generated URL is correct.\n" +
-                                                  "      .setUrl(android.net.Uri.parse(\"%3$s\"))\n" +
-                                                  "      .build();\n" +
-                                                  "  return new %4$s.Builder(%4$s.TYPE_VIEW)\n" +
-                                                  "      .setObject(object)\n" +
-                                                  "      .setActionStatus(%4$s.STATUS_TYPE_COMPLETED)\n" +
-                                                  "      .build();\n" +
+                                                  "  return %5$s.newView(\"%2$s\", \"%3$s\");\n" +
                                                   "}";
 
-  static private final String CLIENT_FORMAT = "%1$s = new %2$s.Builder(this).addApi(%3$s.API).build();";
-  static private final String BUILDER_APPINDEXAPI = ".addApi(%s.API)";
-  static private final String APP_INDEXING_START = "%3$s.AppIndexApi.start(%1$s,%2$s);";
-  static private final String APP_INDEXING_END = "%3$s.AppIndexApi.end(%1$s,%2$s);";
-  static private final String APP_INDEXING_START_HALF = "AppIndexApi.start(%1$s,";
-  static private final String APP_INDEXING_END_HALF = "AppIndexApi.end(%1$s,";
-  static private final String APP_INDEXING_VIEW = "AppIndexApi.view(%1$s,";
-  static private final String APP_INDEXING_VIEWEND = "AppIndexApi.viewEnd(%1$s,";
+  static private final String FIREBASE_USER_ACTION_START_TEMPLATE = "%1$s.getInstance().start(%2$s());";
+  static private final String FIREBASE_USER_ACTION_END_TEMPLATE = "%1$s.getInstance().end(%2$s());";
+  // Constant to look up existing usage.
+  static private final String FIREBASE_USER_ACTION_START = "FirebaseUserActions.getInstance().start";
+  // Constant to look up existing usage.
+  static private final String FIREBASE_USER_ACTION_END = "FirebaseUserActions.getInstance().end";
 
-  static private final List<String> COMMENT_BUILDER_APPINDEXAPI = Lists
-    .newArrayList("// ATTENTION: This \"addApi(AppIndex.API)\"was auto-generated to implement the App Indexing API.",
-                  "// See https://g.co/AppIndexing/AndroidStudio for more information.");
   static private final List<String> COMMENT_IN_JAVA = Lists
     .newArrayList("// ATTENTION: This was auto-generated to implement the App Indexing API.",
                   "// See https://g.co/AppIndexing/AndroidStudio for more information.");
-  static private final String COMMENT_FOR_FIELD = "/**\n" +
-                                                  " * ATTENTION: This %1$swas auto-generated to implement the App Indexing API.\n" +
-                                                  " * See https://g.co/AppIndexing/AndroidStudio for more information.\n" +
-                                                  " */";
-  static private final String COMMENT_IN_MANIFEST =
-    "<!-- ATTENTION: This was auto-generated to add Google Play services to your project for\n" +
-    "     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->";
-
   /* To prompt developers to update deep link url, sets default url to a noticeable wrong url */
   static private final String DEFAULT_DEEP_LINK_URL = "http://[ENTER-YOUR-URL-HERE]";
 
+  // Dependencies list of App Indexing API.
+  // It should be compatible with https://firebase.google.com/docs/app-indexing/android/app
+  // We'll check if all dependencies are added to project and module build.gradle files before generating code.
+  private static final String APP_INDEXING_LIB_DEPENDENCY = "com.google.firebase:firebase-appindexing:10.0.1+";
+  private static final String APP_INDEXING_CLASSPATH_DEPENDENCY = "com.google.gms:google-services:3.0.0+";
+  private static final String APP_INDEXING_PLUGIN_DEPENDENCY = "com.google.gms.google-services";
 
   private Project myProject = null;
   private Module myModule = null;
@@ -170,18 +129,12 @@
   private PsiElementFactory myFactory = null;
   private CodeStyleManager myCodeStyleManager = null;
 
-  private PsiCodeBlock myOnCreate = null;
   private PsiCodeBlock myOnStart = null;
   private PsiCodeBlock myOnStop = null;
 
   /* The App Indexing API statements in onStart / onStop method */
   private List<PsiStatement> myStartStatements = Lists.newArrayList();
   private List<PsiStatement> myEndStatements = Lists.newArrayList();
-  private List<PsiStatement> myViewStatements = Lists.newArrayList();
-  private List<PsiStatement> myViewEndStatements = Lists.newArrayList();
-
-  private String myHighestGmsLibVersion = null;
-  private String myAppIndexingLibVersion = null;
 
   private Map<String, String> myImportClasses = Maps.newHashMap();
 
@@ -195,16 +148,13 @@
       if (element != null) {
         myActivity = getSurroundingInheritingClass(element, SdkConstants.CLASS_ACTIVITY);
         if (myActivity != null) {
-          myOnCreate = getMethodBodyByName("onCreate", SIGNATURE_ON_CREATE, myActivity);
           myOnStart = getMethodBodyByName("onStart", SIGNATURE_ON_START, myActivity);
           myOnStop = getMethodBodyByName("onStop", SIGNATURE_ON_STOP, myActivity);
           if (myOnStart != null) {
-            myStartStatements = StatementFilter.filterCodeBlock("AppIndex.AppIndexApi.start", myOnStart);
-            myViewStatements = StatementFilter.filterCodeBlock("AppIndex.AppIndexApi.view", myOnStart);
+            myStartStatements = StatementFilter.filterCodeBlock(FIREBASE_USER_ACTION_START, myOnStart);
           }
           if (myOnStop != null) {
-            myEndStatements = StatementFilter.filterCodeBlock("AppIndex.AppIndexApi.end", myOnStop);
-            myViewEndStatements = StatementFilter.filterCodeBlock("AppIndex.AppIndexApi.viewEnd", myOnStop);
+            myEndStatements = StatementFilter.filterCodeBlock(FIREBASE_USER_ACTION_END, myOnStop);
           }
         }
       }
@@ -212,15 +162,8 @@
     myFactory = (PsiElementFactory)JVMElementFactories.getFactory(JavaLanguage.INSTANCE, myProject);
     myCodeStyleManager = CodeStyleManager.getInstance(myProject);
     myImportClasses.put(CLASS_ACTION, CLASS_ACTION_FULL);
-    myImportClasses.put(CLASS_APP_INDEX, CLASS_APP_INDEX_FULL);
-    myImportClasses.put(CLASS_GOOGLE_API_CLIENT, CLASS_GOOGLE_API_CLIENT_FULL);
-    myImportClasses.put(CLASS_THING, CLASS_THING_FULL);
-  }
-
-  @VisibleForTesting
-  void setGmsLibVersion(@Nullable String version) {
-    myHighestGmsLibVersion = version;
-    myAppIndexingLibVersion = version;
+    myImportClasses.put(CLASS_BUILDERS_ACTIONS, CLASS_BUILDERS_ACTIONS_FULL);
+    myImportClasses.put(CLASS_FIREBASE_USER_ACTION, CLASS_FIREBASE_USER_ACTION_FULL);
   }
 
   /**
@@ -236,217 +179,49 @@
     if (element == null) return false;
     PsiClass activity = getSurroundingInheritingClass(element, SdkConstants.CLASS_ACTIVITY);
     if (activity == null) return false;
+    if (!hasEnoughDependencies(ModuleUtilCore.findModuleForPsiElement(element))) return false;
     PsiCodeBlock onStart = getMethodBodyByName("onStart", SIGNATURE_ON_START, activity);
     if (onStart == null) return true;
     PsiCodeBlock onStop = getMethodBodyByName("onStop", SIGNATURE_ON_STOP, activity);
     if (onStop == null) return true;
-    List<PsiStatement> startStatements = StatementFilter.filterCodeBlock("AppIndexApi.start", onStart);
-    List<PsiStatement> viewStatements = StatementFilter.filterCodeBlock("AppIndexApi.view", onStart);
-    if (startStatements.isEmpty() && viewStatements.isEmpty()) return true;
-    List<PsiStatement> endStatements = StatementFilter.filterCodeBlock("AppIndexApi.end", onStop);
-    List<PsiStatement> viewEndStatements = StatementFilter.filterCodeBlock("AppIndexApi.viewEnd", onStop);
-    if (endStatements.isEmpty() && viewEndStatements.isEmpty()) return true;
+    List<PsiStatement> startStatements = StatementFilter.filterCodeBlock(FIREBASE_USER_ACTION_START, onStart);
+    if (startStatements.isEmpty()) return true;
+    List<PsiStatement> endStatements = StatementFilter.filterCodeBlock(FIREBASE_USER_ACTION_END, onStop);
+    if (endStatements.isEmpty()) return true;
     return false;
   }
 
+
   /**
    * Inserts the AppIndexing API code for the activity where the caret is in.
-   * Steps:
-   * 1. Generates Google Play Service Support in build.gradle and AndroidManifest.xml of current
-   * module.
-   * 2. Generates App Indexing API code in Java source file.
-   * 3. Sync the project if build.gradle of module is changed.
    */
+
   public void insertAppIndexingApiCodeForActivity() {
-    boolean needGradleSync = false;
-    try {
-      if (myModule == null || myActivity == null || myFactory == null || myCodeStyleManager == null) {
-        Logger.getInstance(ApiCreator.class).info("Unable to generate App Indexing API code.");
-        return;
-      }
-
-      getGmsDependencyVersion();
-      needGradleSync = insertGmsCompileDependencyInGradleIfNeeded();
-
-      XmlFile manifestPsiFile = ManifestUtils.getAndroidManifestPsi(myModule);
-      if (manifestPsiFile == null) {
-        Logger.getInstance(ApiCreator.class).info("AndroidManifest.xml not found.");
-        return;
-      }
-      insertGmsVersionTagInManifestIfNeeded(manifestPsiFile);
-
-      insertAppIndexingApiCodeInJavaFile(getDeepLinkOfActivity(), !needGradleSync);
+    if (myModule == null || myActivity == null || myFactory == null || myCodeStyleManager == null) {
+      Logger.getInstance(ApiCreator.class).info("Unable to generate App Indexing API code.");
+      return;
     }
-    catch (ApiCreatorException e) {
-      e.printStackTrace();
-    }
-    finally {
-      if (needGradleSync) {
-        GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(myProject, null);
-      }
-    }
+    insertAppIndexingApiCodeInJavaFile(getDeepLinkOfActivity());
   }
 
-  private void getGmsDependencyVersion() throws ApiCreatorException {
-    AndroidModuleModel model = AndroidModuleModel.get(myModule);
-    if (model == null) {
-      throw new ApiCreatorException("AndroidGradleModel not found.");
-    }
-    AndroidArtifact artifact = model.getMainArtifact();
-    Dependencies dependencies = getDependencies(artifact, model.getModelVersion());
-    Collection<AndroidLibrary> libraries = dependencies.getLibraries();
-    for (AndroidLibrary library : libraries) {
-      getDependencyVersionFromAndroidLibrary(library);
-    }
-  }
-
-  private void getDependencyVersionFromAndroidLibrary(AndroidLibrary library) {
-    MavenCoordinates coordinates = library.getResolvedCoordinates();
-    if (coordinates != null && coordinates.getGroupId().equals(COMPILE_GMS_GROUP)) {
-      String version = coordinates.getVersion();
-      if (coordinates.getArtifactId().equals(COMPILE_APPINDEXING)) {
-        myAppIndexingLibVersion = version;
-      }
-      if (myHighestGmsLibVersion == null || compareVersion(version, myHighestGmsLibVersion) > 0) {
-        myHighestGmsLibVersion = version;
-      }
-    }
-
-    for (AndroidLibrary dependency : library.getLibraryDependencies()) {
-      getDependencyVersionFromAndroidLibrary(dependency);
-    }
-  }
-
-  /**
-   * Generates App Indexing Support in build.gradle of app module, if no such support exists.
-   *
-   * @return true if gradle myFile is changed and needs sync.
-   */
-  @VisibleForTesting
-  boolean insertGmsCompileDependencyInGradleIfNeeded() throws ApiCreatorException {
-    GradleBuildModel buildModel = GradleBuildModel.get(myModule);
-    if (buildModel == null) {
-      throw new ApiCreatorException("Build model not found.");
-    }
-    DependenciesModel dependencies = buildModel.dependencies();
-    String versionToUse = MINIMUM_VERSION;
-    if (myHighestGmsLibVersion != null && compareVersion(myHighestGmsLibVersion, MINIMUM_VERSION) > 0) {
-      versionToUse = myHighestGmsLibVersion;
-    }
-
-    boolean gradleChange = false;
-    if (myAppIndexingLibVersion == null) {
-      ArtifactDependencySpec newDependency = new ArtifactDependencySpec(COMPILE_APPINDEXING, COMPILE_GMS_GROUP, versionToUse);
-      dependencies = buildModel.dependencies();
-      dependencies.addArtifact(COMPILE, newDependency);
-      buildModel.applyChanges();
-      gradleChange = true;
-    }
-
-    if (myHighestGmsLibVersion != null && compareVersion(myHighestGmsLibVersion, versionToUse) < 0) {
-      List<ArtifactDependencyModel> dependencyList = dependencies.artifacts();
-      for (ArtifactDependencyModel dependency : dependencyList) {
-        String group = dependency.group().value();
-        if (group != null && group.equals(COMPILE_GMS_GROUP)) {
-          dependency.setVersion(versionToUse);
-          buildModel.applyChanges();
-          gradleChange = true;
-        }
-      }
-    }
-    return gradleChange;
-  }
-
-  /**
-   * Generates App Indexing Support in AndroidManifest.xml.
-   *
-   * @param manifestPsiFile The psi file of AndroidManifest.xml.
-   */
-  @VisibleForTesting
-  void insertGmsVersionTagInManifestIfNeeded(@NotNull XmlFile manifestPsiFile) {
-    XmlTag root = manifestPsiFile.getRootTag();
-    if (root != null) {
-      List<XmlTag> applications = ManifestUtils.searchXmlTagsByName(root, SdkConstants.TAG_APPLICATION);
-      for (XmlTag application : applications) {
-        if (getGmsTag(application) == null) {
-          XmlTag gms = application.createChildTag(TAG_METADATA, null, null, false);
-          gms = application.addSubTag(gms, false);
-          gms.setAttribute(SdkConstants.ATTR_NAME, SdkConstants.ANDROID_URI, ATTR_NAME_METADATA_GMS);
-          gms.setAttribute(SdkConstants.ATTR_VALUE, SdkConstants.ANDROID_URI, ATTR_VALUE_METADATA_GMS);
-
-          XmlTag GmsTag = getGmsTag(application);
-          XmlComment comment = createXmlComment(COMMENT_IN_MANIFEST);
-          if (comment != null && GmsTag != null) {
-            application.addBefore(comment, GmsTag);
-          }
-        }
-      }
-      unlockFromPsiOperation(manifestPsiFile);
-    }
-  }
 
   /**
    * Generates App Indexing API code in Java source file.
    * Steps:
    * 1. Generates import statements in activity class.
-   * 2. Generates GoogleApiClient variable.
-   * The method will firstly scan the code to find existing App Indexing API call to get
-   * GoogleApiClient candidate. Then verify if the candidate could be reused in the generated
-   * code - it's a class member and the initialization can be adjusted to add App Indexing API.
-   * If not, a new GoogleApiClient class member will be created.
-   * 3. Generates App Indexing API call in activity.
+   * 2. Generates App Indexing API call in activity.
    *
-   * @param deepLink                  The deep link for the activity. It may be nullable, because
-   *                                  we should deal with situation where no deep link is specified
-   *                                  in AndroidManifest.xml.
-   * @param withAppIndexingDependency If gradle will be sync later.
+   * @param deepLink The deep link for the activity. It may be nullable, because
+   *                 we should deal with situation where no deep link is specified
+   *                 in AndroidManifest.xml.
    */
   @VisibleForTesting
-  void insertAppIndexingApiCodeInJavaFile(@Nullable String deepLink, boolean withAppIndexingDependency) {
-    insertImportStatements(withAppIndexingDependency);
+  void insertAppIndexingApiCodeInJavaFile(@Nullable String deepLink) {
+    insertImportStatements();
 
-    String clientName = null, clientNameCandidate = null;
-    List<PsiStatement> statementsAppIndexApi = getAppIndexApiStatement();
-    for (PsiStatement statementAppIndexApi : statementsAppIndexApi) {
-      clientNameCandidate = getClientInAppIndexingApi(statementAppIndexApi);
-      if (clientNameCandidate != null) {
-        break;
-      }
-    }
-    if (clientNameCandidate == null) {
-      List<String> clientNames = getFieldNameByType(CLASS_GOOGLE_API_CLIENT);
-      if (!clientNames.isEmpty()) {
-        clientNameCandidate = clientNames.get(0);
-      }
-    }
-    if (clientNameCandidate != null) {
-      PsiField clientField = getFieldByName(clientNameCandidate);
-      PsiStatement clientInitStatement = null;
-      if (clientField != null && !clientField.hasInitializer()) {
-        clientInitStatement = getClientInitStatements(clientNameCandidate);
-      }
-      // Adjusts client's initialization to add AppIndexing API.
-      if (clientField != null) {
-        boolean adjustmentSucceed = false;
-        if (clientField.hasInitializer()) {
-          adjustmentSucceed = adjustClientFieldInitializerIfNeeded(clientField);
-        }
-        else if (clientInitStatement != null) {
-          adjustmentSucceed = adjustClientInitStatementIfNeeded(clientInitStatement);
-        }
-        if (adjustmentSucceed) {
-          clientName = clientNameCandidate;
-        }
-      }
-    }
-    if (clientName == null) {
-      // Creates a class member with GoogleApiClient type, and initializes it at onCreate method.
-      clientName = createGoogleApiClientField();
-    }
-
-    String getActionMethodCallText = insertGetActionMethod(deepLink) + "()";
-    addOrMergeOnStart(clientName, getActionMethodCallText);
-    addOrMergeOnStop(clientName, getActionMethodCallText);
+    String getActionMethodCallText = insertGetActionMethod(deepLink);
+    addOrMergeOnStart(getActionMethodCallText);
+    addOrMergeOnStop(getActionMethodCallText);
 
     JavaCodeStyleManager.getInstance(myProject).shortenClassReferences(myActivity);
 
@@ -455,6 +230,7 @@
 
   /**
    * Insert a method which construct Action instance and return it. Return the name of the method inserted.
+   *
    * @param deepLink The deeplink used to construct the Action instance.
    * @return The name of the method inserted.
    */
@@ -462,12 +238,10 @@
   private String insertGetActionMethod(@Nullable String deepLink) {
     String methodName = getUnusedMethodName(METHOD_GET_ACTION);
     String pageName = myActivity.getName();
-    if (pageName.endsWith("Activity")) {
-      pageName = pageName.substring(0, pageName.length() - 8);
-    }
+    pageName = pageName == null ? "" : StringUtil.trimEnd(pageName, "Activity");
     String url = deepLink == null ? DEFAULT_DEEP_LINK_URL : deepLink;
     String getActionMethod = String.format(
-        GET_ACTION_FORMAT, methodName, pageName, url, myImportClasses.get(CLASS_ACTION), myImportClasses.get(CLASS_THING));
+      GET_ACTION_FORMAT, methodName, pageName, url, myImportClasses.get(CLASS_ACTION), myImportClasses.get(CLASS_BUILDERS_ACTIONS));
     PsiMethod newGetAction = myFactory.createMethodFromText(getActionMethod, null);
     myActivity.add(newGetAction);
     return methodName;
@@ -485,23 +259,19 @@
       unusedMethodName = methodName + suffix;
     }
     return unusedMethodName;
-  };
+  }
 
   /**
    * Generates import statements of app indexing Java Code.
-   *
-   * @param withAppIndexingDependency If gradle will be sync later.
    */
-  private void insertImportStatements(boolean withAppIndexingDependency) {
-    if (!withAppIndexingDependency) {
-      // Without App Indexing dependency, App-Indexing-related classes cannot be found,
-      // so "shortenClassReferences" cannot be used.
-      for (Map.Entry<String, String> className : myImportClasses.entrySet()) {
-        if (!ImportUtils.hasOnDemandImportConflict(className.getValue(), myActivity) &&
-            !hasExactImportConflict(className.getValue(), (PsiJavaFile)myFile)) {
-          insertSingleImportIfNeeded(className.getValue());
-          className.setValue(className.getKey());
-        }
+  private void insertImportStatements() {
+    // Without App Indexing dependency, App-Indexing-related classes cannot be found,
+    // so "shortenClassReferences" cannot be used.
+    for (Map.Entry<String, String> className : myImportClasses.entrySet()) {
+      if (!ImportUtils.hasOnDemandImportConflict(className.getValue(), myActivity) &&
+          !hasExactImportConflict(className.getValue(), (PsiJavaFile)myFile)) {
+        insertSingleImportIfNeeded(className.getValue());
+        className.setValue(className.getKey());
       }
     }
   }
@@ -531,353 +301,60 @@
     return false;
   }
 
-
   /**
-   * Searches App Indexing API call in onStart & onStop.
+   * Generates app indexing api calls in onStart method.
    *
-   * @return All the App Indexing API call found.
+   * @param getActionMethodCallText The name of the method getAction.
    */
-  @NotNull
-  private List<PsiStatement> getAppIndexApiStatement() {
-    List<PsiStatement> result = Lists.newArrayList(myStartStatements);
-    result.addAll(myViewStatements);
-    if (!result.isEmpty()) {
-      return result;
-    }
-    result.addAll(myEndStatements);
-    result.addAll(myViewEndStatements);
-    return result;
-  }
-
-  /**
-   * Gets all assignment statements of the client in onCreate.
-   *
-   * @param clientName The GoogleApiClient name.
-   * @return All the init statements.
-   */
-  @Nullable
-  private PsiStatement getClientInitStatements(@NotNull String clientName) {
-    if (myOnCreate != null) {
-      List<PsiStatement> statements = StatementFilter.filterCodeBlock(".build()", myOnCreate);
-      for (PsiStatement statement : statements) {
-        if (statement instanceof PsiExpressionStatement) {
-          PsiType statementType = ((PsiExpressionStatement)statement).getExpression().getType();
-          if (statementType != null &&
-              statementType.getPresentableText().equals(CLASS_GOOGLE_API_CLIENT) &&
-              CharMatcher.WHITESPACE.removeFrom(statement.getText()).startsWith(clientName + "=")) {
-            return statement;
-          }
-        }
-      }
-    }
-    return null;
-  }
-
-  /**
-   * Adjusts the initializer of the client field to add App Indexing API,
-   * if there is the initializer ends with ".build()" and have not added App Indexing API.
-   *
-   * @param clientField The client field.
-   * @return true if the adjustment succeeds, i.e. the initializer has added App Indexing API.
-   */
-  private boolean adjustClientFieldInitializerIfNeeded(@NotNull PsiField clientField) {
-    PsiExpression clientInitializer = clientField.getInitializer();
-    if (clientInitializer != null) {
-      String oldInitializerText = clientInitializer.getText();
-      String newInitializerText = generateApiClientInitializeString(oldInitializerText);
-      if (newInitializerText != null) {
-        if (!newInitializerText.equals(oldInitializerText)) {
-          clientField.setInitializer(myFactory.createExpressionFromText(newInitializerText, null));
-          String commentText = String.format(COMMENT_FOR_FIELD, "\"addApi(AppIndex.API)\" ");
-          myActivity.addBefore(myFactory.createCommentFromText(commentText, null), clientField);
-        }
-        return true;
-      }
-    }
-    return false;
-  }
-
-  /**
-   * Adjusts the the client initializing statement to add AppIndexing API,
-   * if there is the initializer ends with ".build()" and have not added App Indexing API.
-   *
-   * @param statement The init statement of client.
-   * @return true if the adjustment succeeds, i.e. the statement has added App Indexing API.
-   */
-  private boolean adjustClientInitStatementIfNeeded(@NotNull PsiStatement statement) {
-    String oldText = statement.getText();
-    String newText = generateApiClientInitializeString(oldText);
-    if (newText != null) {
-      PsiElement newStatement = statement.replace(myFactory.createStatementFromText(newText, null));
-      if (!newText.equals(oldText)) {
-        addCommentsBefore(COMMENT_BUILDER_APPINDEXAPI, myOnCreate, newStatement);
-      }
-      return true;
-    }
-    return false;
-  }
-
-  /**
-   * Creates a class member with GoogleApiClient type, and initializes it at onCreate method.
-   *
-   * @return The GoogleApiClient name.
-   */
-  @NotNull
-  private String createGoogleApiClientField() {
-    String clientName = getUnusedName("client", VariableKind.FIELD);
-    PsiClassType type = myFactory.createTypeByFQClassName(myImportClasses.get(CLASS_GOOGLE_API_CLIENT));
-    PsiField clientField = (PsiField)myActivity.add(myFactory.createField(clientName, type));
-    myCodeStyleManager.reformat(myActivity);
-    String comment = String.format(COMMENT_FOR_FIELD, "");
-    myActivity.addBefore(myFactory.createCommentFromText(comment, null), clientField);
-    generateGoogleApiClientInitializationInOnCreate(clientName);
-    return clientName;
-  }
-
-  /**
-   * Generates GoogleApiClient initialization in onCreate method.
-   * Used when there is no initializing statement before.
-   *
-   * @param clientName The GoogleApiClient name.
-   */
-  private void generateGoogleApiClientInitializationInOnCreate(@NotNull String clientName) {
-    if (myOnCreate == null) {
-      String onCreateMethod =
-        String.format(ON_CREATE_FORMAT, clientName, myImportClasses.get(CLASS_GOOGLE_API_CLIENT), myImportClasses.get(CLASS_APP_INDEX));
-      PsiMethod newOnCreate = myFactory.createMethodFromText(onCreateMethod, null);
-      myActivity.add(newOnCreate);
-    }
-    else {
-      String initText =
-        String.format(CLIENT_FORMAT, clientName, myImportClasses.get(CLASS_GOOGLE_API_CLIENT), myImportClasses.get(CLASS_APP_INDEX));
-      PsiElement initStatement = myOnCreate.add(myFactory.createStatementFromText(initText, null));
-      addCommentsBefore(COMMENT_IN_JAVA, myOnCreate, initStatement);
-    }
-  }
-
-  /**
-   * Generates app indexing api calls (GoogleApiClient's connect & start) in onStart method.
-   *
-   * @param clientName     The GoogleApiClient name.
-   * @param getActionMethodCallText The text of method call for get action.
-   */
-  private void addOrMergeOnStart(@NotNull String clientName, @NotNull String getActionMethodCallText) {
+  private void addOrMergeOnStart(@NotNull String getActionMethodCallText) {
     if (myOnStart == null) {
-      String onStartMethod = String.format(ON_START_FORMAT, clientName, getActionMethodCallText, myImportClasses.get(CLASS_APP_INDEX));
+      String onStartMethod =
+        String.format(ON_START_FORMAT, myImportClasses.get(CLASS_FIREBASE_USER_ACTION), getActionMethodCallText);
       myActivity.add(myFactory.createMethodFromText(onStartMethod, null));
+      return;
     }
-    else {
-      String connectCall = clientName + ".connect();";
-      List<PsiStatement> connectStatements = StatementFilter.filterCodeBlock(connectCall, myOnStart);
-      // Creates connect() if needed. It should be on the top.
-      if (connectStatements.isEmpty()) {
-        PsiStatement connectStatement = myFactory.createStatementFromText(connectCall, null);
-        List<PsiStatement> superOnStartStatements = StatementFilter.filterCodeBlock("super.onStart();", myOnStart);
-        if (!superOnStartStatements.isEmpty()) {
-          // Adds connect() statement after "super.onStart();".
-          connectStatement = (PsiStatement)myOnStart.addAfter(connectStatement, superOnStartStatements.get(0));
-          addCommentsBefore(COMMENT_IN_JAVA, myOnStart, connectStatement);
-        }
-        else {
-          // Adds connect() statement after "{" in the code block.
-          connectStatement = (PsiStatement)myOnStart.addAfter(connectStatement, myOnStart.getFirstBodyElement());
-          addCommentsBefore(COMMENT_IN_JAVA, myOnStart, connectStatement);
-        }
-      }
-      String startTextHalf = String.format(APP_INDEXING_START_HALF, clientName);
-      myStartStatements = StatementFilter.filterStatements(startTextHalf, myStartStatements);
-      String viewText = String.format(APP_INDEXING_VIEW, clientName);
-      myViewStatements = StatementFilter.filterStatements(viewText, myViewStatements);
-      // Creates Action variable and AppIndex.AppIndexApi.start() at the bottom.
-      if (myStartStatements.isEmpty() && myViewStatements.isEmpty()) {
-        String startText = String.format(APP_INDEXING_START, clientName, getActionMethodCallText, myImportClasses.get(CLASS_APP_INDEX));
-        PsiElement startStatement = myFactory.createStatementFromText(startText, null);
-        startStatement = myOnStart.add(startStatement);
-        addCommentsBefore(COMMENT_IN_JAVA, myOnStart, startStatement);
-      }
+    //  AppIndex.AppIndexApi.start() at the bottom.
+    if (myStartStatements.isEmpty()) {
+      String startText =
+        String.format(FIREBASE_USER_ACTION_START_TEMPLATE, myImportClasses.get(CLASS_FIREBASE_USER_ACTION), getActionMethodCallText);
+      PsiElement startStatement = myFactory.createStatementFromText(startText, null);
+      startStatement = myOnStart.add(startStatement);
+      addCommentsBefore(COMMENT_IN_JAVA, myOnStart, startStatement);
     }
   }
 
   /**
-   * Generates app indexing api calls (GoogleApiClient's disconnect & end) in onStop method.
+   * Generates app indexing api calls in onStop method.
    *
-   * @param clientName     The GoogleApiClient name.
-   * @param getActionMethodCallText The text of method call for get action.
+   * @param getActionMethodCallText The name of the method getAction.
    */
-  private void addOrMergeOnStop(@NotNull String clientName, @NotNull String getActionMethodCallText) {
+  private void addOrMergeOnStop(@NotNull String getActionMethodCallText) {
     if (myOnStop == null) {
-      String onStopMethod = String.format(ON_STOP_FORMAT, clientName, getActionMethodCallText, myImportClasses.get(CLASS_APP_INDEX));
+      String onStopMethod = String.format(ON_STOP_FORMAT, myImportClasses.get(CLASS_FIREBASE_USER_ACTION), getActionMethodCallText);
       myActivity.add(myFactory.createMethodFromText(onStopMethod, null));
+      return;
+    }
+
+    if (!myEndStatements.isEmpty()) {
+      return;
+    }
+    // Creates Action variable and AppIndex.AppIndexApi.end() on the top.
+    PsiStatement endStatement = myFactory.createStatementFromText(
+      String.format(FIREBASE_USER_ACTION_END_TEMPLATE, myImportClasses.get(CLASS_FIREBASE_USER_ACTION), getActionMethodCallText), null);
+    List<PsiStatement> superOnStopStatements = StatementFilter.filterCodeBlock("super.onStop();", myOnStop);
+    if (!superOnStopStatements.isEmpty()) {
+      // after "super.onStop();"
+      endStatement = (PsiStatement)myOnStop.addAfter(endStatement, superOnStopStatements.get(0));
+      addCommentsBefore(COMMENT_IN_JAVA, myOnStop, endStatement);
     }
     else {
-      String disconnectCall = clientName + ".disconnect();";
-      List<PsiStatement> disconnectStatements = StatementFilter.filterCodeBlock(disconnectCall, myOnStop);
-      // Creates disconnect() if needed. It should be at the bottom.
-      if (disconnectStatements.isEmpty()) {
-        PsiElement disconnectStatement = myOnStop.add(myFactory.createStatementFromText(disconnectCall, null));
-        addCommentsBefore(COMMENT_IN_JAVA, myOnStop, disconnectStatement);
-      }
-      String endTextHalf = String.format(APP_INDEXING_END_HALF, clientName);
-      myEndStatements = StatementFilter.filterStatements(endTextHalf, myEndStatements);
-      String viewEndText = String.format(APP_INDEXING_VIEWEND, clientName);
-      myViewEndStatements = StatementFilter.filterStatements(viewEndText, myViewEndStatements);
-      // Creates Action variable and AppIndex.AppIndexApi.end() on the top.
-      if (myEndStatements.isEmpty() && myViewEndStatements.isEmpty()) {
-        String endText = String.format(APP_INDEXING_END, clientName, getActionMethodCallText, myImportClasses.get(CLASS_APP_INDEX));
-        PsiStatement endStatement = myFactory.createStatementFromText(endText, null);
-        List<PsiStatement> superOnStopStatements = StatementFilter.filterCodeBlock("super.onStop();", myOnStop);
-        if (!superOnStopStatements.isEmpty()) {
-          // after "super.onStop();"
-          endStatement = (PsiStatement)myOnStop.addAfter(endStatement, superOnStopStatements.get(0));
-          addCommentsBefore(COMMENT_IN_JAVA, myOnStop, endStatement);
-        }
-        else {
-          // after "{" in the code block.
-          endStatement = (PsiStatement)myOnStop.addAfter(endStatement, myOnStop.getFirstBodyElement());
-          addCommentsBefore(COMMENT_IN_JAVA, myOnStop, endStatement);
-        }
-      }
+      // after "{" in the code block.
+      endStatement = (PsiStatement)myOnStop.addAfter(endStatement, myOnStop.getFirstBodyElement());
+      addCommentsBefore(COMMENT_IN_JAVA, myOnStop, endStatement);
     }
   }
 
   /**
-   * Compares two versions in the form of "12.3.456" etc.
-   *
-   * @return < 0 if version1 < version2; = 0 if version1 = version2; > 0 if version1 > version2
-   */
-  private static int compareVersion(@NotNull String version1, @NotNull String version2) {
-    GradleCoordinate coordinate1 = GradleCoordinate.parseVersionOnly(version1);
-    GradleCoordinate coordinate2 = GradleCoordinate.parseVersionOnly(version2);
-    return GradleCoordinate.COMPARE_PLUS_HIGHER.compare(coordinate1, coordinate2);
-  }
-
-  /**
-   * Gets the GMS meta-data tag in the application tag.
-   */
-  @Nullable
-  private static XmlTag getGmsTag(@NotNull XmlTag application) {
-    XmlTag[] children = application.getSubTags();
-    for (XmlTag child : children) {
-      if (child.getName().equalsIgnoreCase(TAG_METADATA)) {
-        String tagName = child.getAttributeValue(SdkConstants.ATTR_NAME, SdkConstants.ANDROID_URI);
-        if (tagName != null && tagName.equals(ATTR_NAME_METADATA_GMS)) {
-          return child;
-        }
-      }
-    }
-    return null;
-  }
-
-  /**
-   * Gets the client name in an app indexing API call statement.
-   */
-  @Nullable
-  private static String getClientInAppIndexingApi(@NotNull PsiStatement statement) {
-    if (statement instanceof PsiExpressionStatement) {
-      // In the form of "AppIndex.AppIndexApi.start(mClient, viewAction);".
-      PsiElement[] children = statement.getChildren();
-      for (PsiElement child : children) {
-        if (child instanceof PsiMethodCallExpression) {
-          String callExpression = ((PsiMethodCallExpression)child).getMethodExpression().getText();
-          callExpression = CharMatcher.WHITESPACE.removeFrom(callExpression);
-          PsiType[] argsType = ((PsiMethodCallExpression)child).getArgumentList().getExpressionTypes();
-          // API start / end has 2 arguments, viewEnd has 3 arguments, and view has 2.
-          // The first arg is GoogleApiClient. If not declared before used, it has a null type.
-          if ((callExpression.startsWith("AppIndex.AppIndexApi.") ||
-               callExpression.startsWith("AppIndexApi") ||
-               callExpression.startsWith(CLASS_APP_INDEX_FULL)) &&
-              (argsType.length == 2 || argsType.length == 3 || argsType.length == 6) &&
-              argsType[0] != null) {
-            PsiExpression[] args = ((PsiMethodCallExpression)child).getArgumentList().getExpressions();
-            String clientName = args[0].getText();
-            if (clientName != null) {
-              return clientName;
-            }
-          }
-        }
-      }
-    }
-    else if (statement instanceof PsiDeclarationStatement) {
-      // In form of "PendingResult<Status> a = AppIndex.AppIndexApi.start(mClient, viewAction);".
-      PsiElement[] children = ((PsiDeclarationStatement)statement).getDeclaredElements();
-      for (PsiElement child : children) {
-        if (child instanceof PsiVariable) {
-          PsiExpression initializer = ((PsiVariable)child).getInitializer();
-          if (initializer != null) {
-            // Initializer is in the form of "AppIndex.AppIndexApi.start(mClient, viewAction)".
-            PsiElement[] initChildren = initializer.getChildren();
-            if (initChildren.length == 2 &&
-                initChildren[0] instanceof PsiReferenceExpression &&
-                initChildren[1] instanceof PsiExpressionList) {
-              // initChildren[0] should be in the form of "AppIndex.AppIndexApi.start".
-              // initChildren[1] should be in the form of "(mClient, ...)".
-              // args should be in the form of {"mClient", ...}. Check its length and type.
-              String referenceExpression = CharMatcher.WHITESPACE.removeFrom(initChildren[0].getText());
-              PsiExpression[] args = ((PsiExpressionList)initChildren[1]).getExpressions();
-              // API start / end has 2 arguments, viewEnd has 3 arguments, and view has 2.
-              // The first arg is GoogleApiClient. If not declared before used, it has a null type.
-              if ((referenceExpression.startsWith("AppIndex.AppIndexApi.") ||
-                   referenceExpression.startsWith("AppIndexApi.") ||
-                   referenceExpression.startsWith(CLASS_APP_INDEX_FULL)) &&
-                  (args.length == 2 || args.length == 3 || args.length == 6) && args[0].getType() != null) {
-                String clientName = args[0].getText();
-                if (clientName != null) {
-                  return clientName;
-                }
-              }
-            }
-          }
-        }
-      }
-    }
-    return null;
-  }
-
-  /**
-   * Generates a name which has not been used.
-   * Example: if "name" is used, "name2" will be returned;
-   * if "name2" is also used, "name3" will be returned; ...
-   *
-   * @param name The initial default name.
-   * @return A name based on the initial name which has not been used.
-   */
-  @NotNull
-  private String getUnusedName(String name, VariableKind kind) {
-    JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(myProject);
-    name = javaCodeStyleManager.suggestVariableName(kind, name, null, null).names[0];
-
-    Set<String> usedName = getUsedVariableName();
-    String unusedName = name;
-    int suffix = 2;
-    while (usedName.contains(unusedName)) {
-      unusedName = name + suffix;
-      suffix++;
-    }
-    return unusedName;
-  }
-
-  /**
-   * Generates GoogleApiClient initializing string.
-   *
-   * @param statementText The original initialize string.
-   * @return The new string.
-   */
-  @Nullable
-  private String generateApiClientInitializeString(@NotNull String statementText) {
-    int splitPoint = statementText.lastIndexOf(".build()");
-    if (!statementText.contains(String.format(BUILDER_APPINDEXAPI, CLASS_APP_INDEX_FULL)) &&
-        !statementText.contains(String.format(BUILDER_APPINDEXAPI, CLASS_APP_INDEX)) && splitPoint != -1) {
-      return statementText.substring(0, splitPoint) +
-             String.format(BUILDER_APPINDEXAPI, myImportClasses.get(CLASS_APP_INDEX)) +
-             statementText.substring(splitPoint);
-    }
-    else if (splitPoint != -1) {
-      return statementText;
-    }
-    return null;
-  }
-
-  /**
    * Returns deep links of current activity in AndroidManifest.xml.
    */
   @Nullable
@@ -900,21 +377,6 @@
   }
 
   /**
-   * Creates xml comment element.
-   *
-   * @param text The text form of comment.
-   * @return The created comment.
-   */
-  @Nullable
-  private XmlComment createXmlComment(@NotNull String text) {
-    // XmlElementFactory does not provide API for creating comment.
-    // So we create a tag wrapping the comment, and extract comment from the created tag.
-    XmlElementFactory xmlElementFactory = XmlElementFactory.getInstance(myProject);
-    XmlTag commentElement = xmlElementFactory.createTagFromText("<foo>" + text + "</foo>", XMLLanguage.INSTANCE);
-    return PsiTreeUtil.getChildOfType(commentElement, XmlComment.class);
-  }
-
-  /**
    * Adds comments before a specific psi element.
    *
    * @param texts   The text of the comments.
@@ -1001,35 +463,6 @@
   }
 
   /**
-   * Gets names of class members, given the type name.
-   *
-   * @param typeName The type presentable name.
-   * @return The members' names
-   */
-  @NotNull
-  private List<String> getFieldNameByType(@NotNull String typeName) {
-    List<String> result = Lists.newArrayList();
-    PsiField[] psiFields = myActivity.getFields();
-    for (PsiField psiField : psiFields) {
-      if (psiField.getType().getPresentableText().equals(typeName)) {
-        result.add(psiField.getName());
-      }
-    }
-    return result;
-  }
-
-  @Nullable
-  private PsiField getFieldByName(@NotNull String name) {
-    PsiField[] psiFields = myActivity.getFields();
-    for (PsiField psiField : psiFields) {
-      if (psiField.getName().equals(name)) {
-        return psiField;
-      }
-    }
-    return null;
-  }
-
-  /**
    * Inserts a single import statement.
    *
    * @param className The name of the import class.
@@ -1063,39 +496,64 @@
     return singleImport != null || onDemandImport != null;
   }
 
+
   /**
-   * Returns all the fields' and local variables' names which have already been used.
+   * Check if the existing dependencies are enough to insert App Indexing code.
+   *
+   * @return true if there are enough dependencies.
    */
-  @NotNull
-  private Set<String> getUsedVariableName() {
-    Set<String> usedNames = Sets.newHashSet();
-    // name of PsiFields in PsiClass
-    PsiField[] psiFields = myActivity.getFields();
-    for (PsiField psiField : psiFields) {
-      usedNames.add(psiField.getName());
+  // TODO: Consider to replace this method with DependencyStateManager.getPendingDependencies method, once it's refactored out from firebase module.
+  static boolean hasEnoughDependencies(@NotNull Module module) {
+    final GradleBuildModel gradleBuildModel = GradleBuildModel.get(module);
+    // Possibly null in scenario such as gradle sync in progress.
+    if (gradleBuildModel == null) {
+      return false;
     }
-    // name of PsiLocalVariables in PsiMethods in PsiClass
-    PsiMethod[] psiMethods = myActivity.getMethods();
-    for (PsiMethod psiMethod : psiMethods) {
-      PsiCodeBlock methodBody = psiMethod.getBody();
-      if (methodBody != null) {
-        List<PsiStatement> psiStatements = StatementFilter.filterCodeBlock("", methodBody);
-        for (PsiStatement psiStatement : psiStatements) {
-          if (psiStatement instanceof PsiDeclarationStatement) {
-            PsiElement[] declaredElements = ((PsiDeclarationStatement)psiStatement).getDeclaredElements();
-            for (PsiElement declaredElement : declaredElements) {
-              usedNames.add(((PsiLocalVariable)declaredElement).getName());
-            }
-          }
-        }
-      }
+    DependenciesModel dependenciesModel = gradleBuildModel.dependencies();
+    if (dependenciesModel == null) {
+      return false;
     }
-    return usedNames;
+    if (!hasDependency(APP_INDEXING_LIB_DEPENDENCY, dependenciesModel.artifacts())) {
+      return false;
+    }
+
+    // Check the plugin dependency.
+    final List<String> plugins = getValues(gradleBuildModel.appliedPlugins());
+    if (!plugins.contains(APP_INDEXING_PLUGIN_DEPENDENCY)) {
+      return false;
+    }
+
+    // Check classpath dependency at the project level.
+    final GradleBuildModel projectGradleBuildModel = GradleBuildModel.get(module.getProject());
+    if (projectGradleBuildModel == null) {
+      return false;
+    }
+    final DependenciesModel dependencies = projectGradleBuildModel.buildscript().dependencies();
+    return hasDependency(APP_INDEXING_CLASSPATH_DEPENDENCY, dependencies.artifacts(CommonConfigurationNames.CLASSPATH));
   }
 
-  static class ApiCreatorException extends Exception {
-    public ApiCreatorException(String message) {
-      super(message);
+  /**
+   * Check if the designated dependency already exists
+   *
+   * @param dependencyValue module or classpath dependency value with version.
+   * @param existingDeps    current existing dependencies.
+   * @return true if the designated dependency already exists.
+   */
+  @NotNull
+  private static boolean hasDependency(@NotNull String dependencyValue,
+                                       @NotNull List<ArtifactDependencyModel> existingDeps) {
+
+    ArtifactDependencySpec requiredDepSpec = ArtifactDependencySpec.create(dependencyValue);
+    if (requiredDepSpec == null) {
+      return true;
     }
+    for (ArtifactDependencyModel dependency : existingDeps) {
+      ArtifactDependencySpec foundDepSpec = ArtifactDependencySpec.create(dependency);
+      if (foundDepSpec.equalsIgnoreVersion(requiredDepSpec) &&
+          VersionComparatorUtil.compare(foundDepSpec.version, requiredDepSpec.version) >= 0) {
+        return true;
+      }
+    }
+    return false;
   }
 }
diff --git a/testData/ApiCreator/src/ActionNotInitialized_after.java b/testData/ApiCreator/src/ActionNotInitialized_after.java
deleted file mode 100644
index 8ff3d57..0000000
--- a/testData/ApiCreator/src/ActionNotInitialized_after.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-    Action viewAction;
-    AppIndex.AppIndexApi.start(client, viewAction);
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    client.disconnect();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-}
diff --git a/testData/ApiCreator/src/ClientField.java b/testData/ApiCreator/src/ClientField.java
deleted file mode 100644
index 690b1ff..0000000
--- a/testData/ApiCreator/src/ClientField.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client = new GoogleApiClient.Builder(this).build();
-}
diff --git a/testData/ApiCreator/src/ClientField_after.java b/testData/ApiCreator/src/ClientField_after.java
deleted file mode 100644
index aa9f8c3..0000000
--- a/testData/ApiCreator/src/ClientField_after.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  /**
-   * ATTENTION: This "addApi(AppIndex.API)" was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  private GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-        .setName("Main Page") // TODO: Define a title for the content shown.
-        // TODO: Make sure this auto-generated URL is correct.
-        .setUrl(Uri.parse("http://www.example.com/main"))
-        .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-        .setObject(object)
-        .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-        .build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    client.disconnect();
-  }
-}
diff --git a/testData/ApiCreator/src/ClientInDeclarationStatement.java b/testData/ApiCreator/src/ClientInDeclarationStatement.java
deleted file mode 100644
index eacdd64..0000000
--- a/testData/ApiCreator/src/ClientInDeclarationStatement.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-import com.google.android.gms.common.api.PendingResult;
-import com.google.android.gms.common.api.Status;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    PendingResult<Status> status = AppIndex.AppIndexApi.start(client, viewAction);
-  }
-}
diff --git a/testData/ApiCreator/src/ClientInDeclarationStatement_after.java b/testData/ApiCreator/src/ClientInDeclarationStatement_after.java
deleted file mode 100644
index b4c8dba..0000000
--- a/testData/ApiCreator/src/ClientInDeclarationStatement_after.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-import com.google.android.gms.common.api.PendingResult;
-import com.google.android.gms.common.api.Status;
-
-public class MainActivity extends Activity {
-
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    PendingResult<Status> status = AppIndex.AppIndexApi.start(client, viewAction);
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    client.disconnect();
-  }
-}
diff --git a/testData/ApiCreator/src/ClientInitializedWithoutBuilder.java b/testData/ApiCreator/src/ClientInitializedWithoutBuilder.java
deleted file mode 100644
index 0d9cffd..0000000
--- a/testData/ApiCreator/src/ClientInitializedWithoutBuilder.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    GoogleApiClient client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-    client = client2;
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.start(client, viewAction);
-  }
-}
diff --git a/testData/ApiCreator/src/ClientInitializedWithoutBuilder_after.java b/testData/ApiCreator/src/ClientInitializedWithoutBuilder_after.java
deleted file mode 100644
index e8751bb..0000000
--- a/testData/ApiCreator/src/ClientInitializedWithoutBuilder_after.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  private GoogleApiClient client;
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  private GoogleApiClient client3;
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client3.connect();
-    GoogleApiClient client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-    client = client2;
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.start(client, viewAction);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.start(client3, getIndexApiAction());
-  }
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client3 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client3, getIndexApiAction());
-    client3.disconnect();
-  }
-}
diff --git a/testData/ApiCreator/src/ClientLocalVariable.java b/testData/ApiCreator/src/ClientLocalVariable.java
deleted file mode 100644
index 74cf129..0000000
--- a/testData/ApiCreator/src/ClientLocalVariable.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page")
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-    client.connect();
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
-  }
-}
diff --git a/testData/ApiCreator/src/ClientLocalVariable_after.java b/testData/ApiCreator/src/ClientLocalVariable_after.java
deleted file mode 100644
index a32e8dd..0000000
--- a/testData/ApiCreator/src/ClientLocalVariable_after.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  private GoogleApiClient client2;
-
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page")
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client2.connect();
-    GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-    client.connect();
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.start(client2, getIndexApiAction0());
-  }
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction0() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client2, getIndexApiAction0());
-    client2.disconnect();
-  }
-}
diff --git a/testData/ApiCreator/src/ClientNotInitialized.java b/testData/ApiCreator/src/ClientNotInitialized.java
deleted file mode 100644
index 4189f09..0000000
--- a/testData/ApiCreator/src/ClientNotInitialized.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.start(client, viewAction);
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    client.disconnect();
-  }
-}
diff --git a/testData/ApiCreator/src/ClientNotInitialized_after.java b/testData/ApiCreator/src/ClientNotInitialized_after.java
deleted file mode 100644
index 9f8c8a7..0000000
--- a/testData/ApiCreator/src/ClientNotInitialized_after.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  private GoogleApiClient client;
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  private GoogleApiClient client2;
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client2.connect();
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.start(client, viewAction);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.start(client2, getIndexApiAction());
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client2, getIndexApiAction());
-    client.disconnect();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client2.disconnect();
-  }
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-}
diff --git a/testData/ApiCreator/src/ConflictGetActionMethodName.java b/testData/ApiCreator/src/ConflictGetActionMethodName.java
new file mode 100644
index 0000000..84d6ba8
--- /dev/null
+++ b/testData/ApiCreator/src/ConflictGetActionMethodName.java
@@ -0,0 +1,13 @@
+package com.example.creation;
+
+import a.Action;
+
+import android.app.Activity;
+
+public class MainActivity extends Activity {
+  <caret>
+
+  public Action getIndexApiAction() {
+    return new Action();
+  }
+}
diff --git a/testData/ApiCreator/src/ConflictGetActionMethodName_after.java b/testData/ApiCreator/src/ConflictGetActionMethodName_after.java
new file mode 100644
index 0000000..d7f66ce
--- /dev/null
+++ b/testData/ApiCreator/src/ConflictGetActionMethodName_after.java
@@ -0,0 +1,40 @@
+package com.example.creation;
+
+import a.Action;
+
+import android.app.Activity;
+import com.google.firebase.appindexing.FirebaseUserActions;
+import com.google.firebase.appindexing.builders.Actions;
+
+public class MainActivity extends Activity {
+
+
+  public Action getIndexApiAction() {
+    return new Action();
+  }
+
+  /**
+   * ATTENTION: This was auto-generated to implement the App Indexing API.
+   * See https://g.co/AppIndexing/AndroidStudio for more information.
+   */
+  public com.google.firebase.appindexing.Action getIndexApiAction0() {
+    return Actions.newView("Main", "http://www.example.com/main");
+  }
+
+  @Override
+  public void onStart() {
+    super.onStart();
+
+    // ATTENTION: This was auto-generated to implement the App Indexing API.
+    // See https://g.co/AppIndexing/AndroidStudio for more information.
+    FirebaseUserActions.getInstance().start(getIndexApiAction0());
+  }
+
+  @Override
+  public void onStop() {
+    // ATTENTION: This was auto-generated to implement the App Indexing API.
+    // See https://g.co/AppIndexing/AndroidStudio for more information.
+    FirebaseUserActions.getInstance().end(getIndexApiAction0());
+    super.onStop();
+  }
+}
\ No newline at end of file
diff --git a/testData/ApiCreator/src/ConflictImports.java b/testData/ApiCreator/src/ConflictImports.java
index 412737b..7b54e9f 100644
--- a/testData/ApiCreator/src/ConflictImports.java
+++ b/testData/ApiCreator/src/ConflictImports.java
@@ -1,9 +1,8 @@
 package com.example.creation;
 
 import a.Action;
-import a.AppIndex;
-import a.GoogleApiClient;
-import a.Thing;
+import a.FirebaseUserActions;
+import a.Actions;
 
 import android.app.Activity;
 
diff --git a/testData/ApiCreator/src/ConflictImports_after.java b/testData/ApiCreator/src/ConflictImports_after.java
index 7c71942..4e29e4b 100644
--- a/testData/ApiCreator/src/ConflictImports_after.java
+++ b/testData/ApiCreator/src/ConflictImports_after.java
@@ -1,13 +1,10 @@
 package com.example.creation;
 
 import a.Action;
-import a.AppIndex;
-import a.GoogleApiClient;
-import a.Thing;
+import a.FirebaseUserActions;
+import a.Actions;
 
 import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
 
 public class MainActivity extends Activity {
 
@@ -15,30 +12,8 @@
    * ATTENTION: This was auto-generated to implement the App Indexing API.
    * See https://g.co/AppIndexing/AndroidStudio for more information.
    */
-  private com.google.android.gms.common.api.GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client = new com.google.android.gms.common.api.GoogleApiClient.Builder(this).addApi(com.google.android.gms.appindexing.AppIndex.API).build();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public com.google.android.gms.appindexing.Action getIndexApiAction() {
-    com.google.android.gms.appindexing.Thing object = new com.google.android.gms.appindexing.Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new com.google.android.gms.appindexing.Action.Builder(com.google.android.gms.appindexing.Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(com.google.android.gms.appindexing.Action.STATUS_TYPE_COMPLETED)
-      .build();
+  public com.google.firebase.appindexing.Action getIndexApiAction() {
+    return com.google.firebase.appindexing.builders.Actions.newView("Main", "http://www.example.com/main");
   }
 
   @Override
@@ -47,17 +22,14 @@
 
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    com.google.android.gms.appindexing.AppIndex.AppIndexApi.start(client, getIndexApiAction());
+    com.google.firebase.appindexing.FirebaseUserActions.getInstance().start(getIndexApiAction());
   }
 
   @Override
   public void onStop() {
-    super.onStop();
-
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    com.google.android.gms.appindexing.AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    client.disconnect();
+    com.google.firebase.appindexing.FirebaseUserActions.getInstance().end(getIndexApiAction());
+    super.onStop();
   }
 }
diff --git a/testData/ApiCreator/src/EmptyActivity_after.java b/testData/ApiCreator/src/EmptyActivity_after.java
index d0efb31..3b8a7a0 100644
--- a/testData/ApiCreator/src/EmptyActivity_after.java
+++ b/testData/ApiCreator/src/EmptyActivity_after.java
@@ -1,13 +1,9 @@
 package com.example.creation;
 
 import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.firebase.appindexing.Action;
+import com.google.firebase.appindexing.FirebaseUserActions;
+import com.google.firebase.appindexing.builders.Actions;
 
 public class MainActivity extends Activity {
 
@@ -15,30 +11,8 @@
    * ATTENTION: This was auto-generated to implement the App Indexing API.
    * See https://g.co/AppIndexing/AndroidStudio for more information.
    */
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
   public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
+    return Actions.newView("Main", "http://www.example.com/main");
   }
 
   @Override
@@ -47,17 +21,14 @@
 
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
   }
 
   @Override
   public void onStop() {
-    super.onStop();
-
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    client.disconnect();
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
+    super.onStop();
   }
-}
+}
\ No newline at end of file
diff --git a/testData/ApiCreator/src/HasAppIndexingStartAndEnd.java b/testData/ApiCreator/src/HasAppIndexingStartAndEnd.java
index 914ce43..3bf88e7 100644
--- a/testData/ApiCreator/src/HasAppIndexingStartAndEnd.java
+++ b/testData/ApiCreator/src/HasAppIndexingStartAndEnd.java
@@ -7,40 +7,28 @@
 import com.google.android.gms.appindexing.Action;
 import com.google.android.gms.appindexing.AppIndex;
 import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.firebase.appindexing.FirebaseUserActions;
+import com.google.firebase.appindexing.builders.Actions;
 
 public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
+
 
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
   }
 
   @Override
   public void onStart() {
     super.onStart();
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.start(client, viewAction);
+    // ATTENTION: This was auto-generated to implement the App Indexing API.
+    // See https://g.co/AppIndexing/AndroidStudio for more information.
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
   }
 
   @Override
   public void onStop() {
     super.onStop();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.end(client, viewAction);
-    client.disconnect();
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
   }
 }
diff --git a/testData/ApiCreator/src/HasAppIndexingViewAndViewEnd.java b/testData/ApiCreator/src/HasAppIndexingViewAndViewEnd.java
deleted file mode 100644
index 49c8d4e..0000000
--- a/testData/ApiCreator/src/HasAppIndexingViewAndViewEnd.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-    AppIndex.AppIndexApi.view(client, this,
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main"),
-        "Main Page", Uri.parse("http://www.example.com/main"), null);
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    AppIndex.AppIndexApi.viewEnd(client, this,
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main"));
-    client.disconnect();
-  }
-}
diff --git a/testData/ApiCreator/src/NoKeywordSuper.java b/testData/ApiCreator/src/NoKeywordSuper.java
index 7d43493..5850ce5 100644
--- a/testData/ApiCreator/src/NoKeywordSuper.java
+++ b/testData/ApiCreator/src/NoKeywordSuper.java
@@ -1,21 +1,20 @@
 package com.example.creation;
 
 import android.app.Activity;
-import android.net.Uri;
 import android.os.Bundle;
 
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
 public class MainActivity extends Activity {
   <caret>
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {}
 
   @Override
-  public void onStart() {}
+  protected void onCreate(Bundle savedInstanceState) {
+  }
 
   @Override
-  public void onStop() {}
+  public void onStart() {
+  }
+
+  @Override
+  public void onStop() {
+  }
 }
diff --git a/testData/ApiCreator/src/NoKeywordSuper_after.java b/testData/ApiCreator/src/NoKeywordSuper_after.java
index df400d0..ba6a959 100644
--- a/testData/ApiCreator/src/NoKeywordSuper_after.java
+++ b/testData/ApiCreator/src/NoKeywordSuper_after.java
@@ -1,47 +1,30 @@
 package com.example.creation;
 
 import android.app.Activity;
-import android.net.Uri;
 import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.firebase.appindexing.Action;
+import com.google.firebase.appindexing.FirebaseUserActions;
+import com.google.firebase.appindexing.builders.Actions;
 
 public class MainActivity extends Activity {
 
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  private GoogleApiClient client;
 
   @Override
   protected void onCreate(Bundle savedInstanceState) {
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
   }
 
   @Override
   public void onStart() {
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
   }
 
   @Override
   public void onStop() {
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.disconnect();
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
   }
 
   /**
@@ -49,14 +32,6 @@
    * See https://g.co/AppIndexing/AndroidStudio for more information.
    */
   public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
+    return Actions.newView("Main", "http://www.example.com/main");
   }
 }
diff --git a/testData/ApiCreator/src/ActionNotInitialized.java b/testData/ApiCreator/src/OnlyEndCall.java
similarity index 70%
rename from testData/ApiCreator/src/ActionNotInitialized.java
rename to testData/ApiCreator/src/OnlyEndCall.java
index 249e93a..f5aac9a 100644
--- a/testData/ApiCreator/src/ActionNotInitialized.java
+++ b/testData/ApiCreator/src/OnlyEndCall.java
@@ -10,25 +10,20 @@
 
 public class MainActivity extends Activity {
   <caret>
-  private GoogleApiClient client;
 
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
   }
 
   @Override
   public void onStart() {
     super.onStart();
-    client.connect();
-    Action viewAction;
-    AppIndex.AppIndexApi.start(client, viewAction);
   }
 
   @Override
   public void onStop() {
     super.onStop();
-    client.disconnect();
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
   }
 }
diff --git a/testData/ApiCreator/src/OnlyEndCallAndAdjustClientInitializingStatement.java b/testData/ApiCreator/src/OnlyEndCallAndAdjustClientInitializingStatement.java
deleted file mode 100644
index 2277c8f..0000000
--- a/testData/ApiCreator/src/OnlyEndCallAndAdjustClientInitializingStatement.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    client = new GoogleApiClient.Builder(this).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.end(client, viewAction);
-  }
-}
diff --git a/testData/ApiCreator/src/OnlyEndCallAndAdjustClientInitializingStatement_after.java b/testData/ApiCreator/src/OnlyEndCallAndAdjustClientInitializingStatement_after.java
deleted file mode 100644
index fe246f0..0000000
--- a/testData/ApiCreator/src/OnlyEndCallAndAdjustClientInitializingStatement_after.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    // ATTENTION: This "addApi(AppIndex.API)" was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.end(client, viewAction);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.disconnect();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-}
diff --git a/testData/ApiCreator/src/OnlyEndCall_after.java b/testData/ApiCreator/src/OnlyEndCall_after.java
new file mode 100644
index 0000000..001f3ca
--- /dev/null
+++ b/testData/ApiCreator/src/OnlyEndCall_after.java
@@ -0,0 +1,42 @@
+package com.example.creation;
+
+import android.app.Activity;
+import android.net.Uri;
+import android.os.Bundle;
+
+import com.google.android.gms.appindexing.Action;
+import com.google.android.gms.appindexing.AppIndex;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.firebase.appindexing.FirebaseUserActions;
+import com.google.firebase.appindexing.builders.Actions;
+
+public class MainActivity extends Activity {
+
+
+  @Override
+  protected void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+  }
+
+  @Override
+  public void onStart() {
+    super.onStart();
+    // ATTENTION: This was auto-generated to implement the App Indexing API.
+    // See https://g.co/AppIndexing/AndroidStudio for more information.
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
+  }
+
+  @Override
+  public void onStop() {
+    super.onStop();
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
+  }
+
+  /**
+   * ATTENTION: This was auto-generated to implement the App Indexing API.
+   * See https://g.co/AppIndexing/AndroidStudio for more information.
+   */
+  public com.google.firebase.appindexing.Action getIndexApiAction() {
+    return Actions.newView("Main", "http://www.example.com/main");
+  }
+}
\ No newline at end of file
diff --git a/testData/ApiCreator/src/OnlyStartCallAndAdjustClientFieldInitializer.java b/testData/ApiCreator/src/OnlyStartCall.java
similarity index 64%
rename from testData/ApiCreator/src/OnlyStartCallAndAdjustClientFieldInitializer.java
rename to testData/ApiCreator/src/OnlyStartCall.java
index 8a46c64..bd104b0 100644
--- a/testData/ApiCreator/src/OnlyStartCallAndAdjustClientFieldInitializer.java
+++ b/testData/ApiCreator/src/OnlyStartCall.java
@@ -15,14 +15,7 @@
   @Override
   public void onStart() {
     super.onStart();
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.start(client, viewAction);
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
   }
 
   @Override
diff --git a/testData/ApiCreator/src/OnlyStartCallAndAdjustClientFieldInitializer_after.java b/testData/ApiCreator/src/OnlyStartCallAndAdjustClientFieldInitializer_after.java
deleted file mode 100644
index da3103a..0000000
--- a/testData/ApiCreator/src/OnlyStartCallAndAdjustClientFieldInitializer_after.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  /**
-   * ATTENTION: This "addApi(AppIndex.API)" was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  private GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-    Action viewAction = Action.newAction(
-        Action.TYPE_VIEW,
-        "Main Page",
-        Uri.parse("http://www.example.com/main"),
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main")
-    );
-    AppIndex.AppIndexApi.start(client, viewAction);
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    client.disconnect();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-}
diff --git a/testData/ApiCreator/src/OnlyStartCall_after.java b/testData/ApiCreator/src/OnlyStartCall_after.java
new file mode 100644
index 0000000..0c43063
--- /dev/null
+++ b/testData/ApiCreator/src/OnlyStartCall_after.java
@@ -0,0 +1,39 @@
+package com.example.creation;
+
+import android.app.Activity;
+import android.net.Uri;
+import android.os.Bundle;
+
+import com.google.android.gms.appindexing.Action;
+import com.google.android.gms.appindexing.AppIndex;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.firebase.appindexing.FirebaseUserActions;
+import com.google.firebase.appindexing.builders.Actions;
+
+public class MainActivity extends Activity {
+
+  private GoogleApiClient client = new GoogleApiClient.Builder(this).build();
+
+  @Override
+  public void onStart() {
+    super.onStart();
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
+  }
+
+  @Override
+  public void onStop() {
+    super.onStop();
+    // ATTENTION: This was auto-generated to implement the App Indexing API.
+    // See https://g.co/AppIndexing/AndroidStudio for more information.
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
+    client.disconnect();
+  }
+
+  /**
+   * ATTENTION: This was auto-generated to implement the App Indexing API.
+   * See https://g.co/AppIndexing/AndroidStudio for more information.
+   */
+  public com.google.firebase.appindexing.Action getIndexApiAction() {
+    return Actions.newView("Main", "http://www.example.com/main");
+  }
+}
\ No newline at end of file
diff --git a/testData/ApiCreator/src/OnlyViewCall.java b/testData/ApiCreator/src/OnlyViewCall.java
deleted file mode 100644
index ed96553..0000000
--- a/testData/ApiCreator/src/OnlyViewCall.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    AppIndex.AppIndexApi.view(client, this,
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main"),
-        "Main Page", Uri.parse("http://www.example.com/main"), null);
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-  }
-}
diff --git a/testData/ApiCreator/src/OnlyViewCall_after.java b/testData/ApiCreator/src/OnlyViewCall_after.java
deleted file mode 100644
index b3c133c..0000000
--- a/testData/ApiCreator/src/OnlyViewCall_after.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    AppIndex.AppIndexApi.view(client, this,
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main"),
-        "Main Page", Uri.parse("http://www.example.com/main"), null);
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.disconnect();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-}
diff --git a/testData/ApiCreator/src/OnlyViewEndCall.java b/testData/ApiCreator/src/OnlyViewEndCall.java
deleted file mode 100644
index 25d4d13..0000000
--- a/testData/ApiCreator/src/OnlyViewEndCall.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-  <caret>
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    AppIndex.AppIndexApi.viewEnd(client, this,
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main"));
-    client.disconnect();
-  }
-}
diff --git a/testData/ApiCreator/src/OnlyViewEndCall_after.java b/testData/ApiCreator/src/OnlyViewEndCall_after.java
deleted file mode 100644
index e3d249e..0000000
--- a/testData/ApiCreator/src/OnlyViewEndCall_after.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.example.creation;
-
-import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-public class MainActivity extends Activity {
-
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  @Override
-  public void onStart() {
-    super.onStart();
-    client.connect();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
-  }
-
-  @Override
-  public void onStop() {
-    super.onStop();
-    AppIndex.AppIndexApi.viewEnd(client, this,
-        Uri.parse("android-app://com.example.creation/http/www.example.com/main"));
-    client.disconnect();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
-  }
-}
diff --git a/testData/ApiCreator/src/OverrideMethod_after.java b/testData/ApiCreator/src/OverrideMethod_after.java
index 1f0f5d9..b457bc8 100644
--- a/testData/ApiCreator/src/OverrideMethod_after.java
+++ b/testData/ApiCreator/src/OverrideMethod_after.java
@@ -1,52 +1,32 @@
 package com.example.creation;
 
 import android.app.Activity;
-import android.net.Uri;
 import android.os.Bundle;
-
-import com.google.android.gms.appindexing.Action;
-import com.google.android.gms.appindexing.AppIndex;
-import com.google.android.gms.appindexing.Thing;
-import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.firebase.appindexing.Action;
+import com.google.firebase.appindexing.FirebaseUserActions;
+import com.google.firebase.appindexing.builders.Actions;
 
 public class MainActivity extends Activity {
 
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
-  private GoogleApiClient client;
-
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
   }
 
   @Override
   public void onStart() {
     super.onStart();
-
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
   }
 
   @Override
   public void onStop() {
     super.onStop();
-
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.disconnect();
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
   }
 
   /**
@@ -54,14 +34,7 @@
    * See https://g.co/AppIndexing/AndroidStudio for more information.
    */
   public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
+    return Actions.newView("Main", "http://www.example.com/main");
   }
 }
+
diff --git a/testData/ApiCreator/src/WildCardImports.java b/testData/ApiCreator/src/WildCardImports.java
index 1b0e783..a6d7ba0 100644
--- a/testData/ApiCreator/src/WildCardImports.java
+++ b/testData/ApiCreator/src/WildCardImports.java
@@ -2,8 +2,7 @@
 
 import android.app.Activity;
 
-import com.google.android.gms.appindexing.*;
-import com.google.android.gms.common.api.*;
+import com.google.firebase.appindexing.*;
 
 public class MainActivity extends Activity {
   <caret>
diff --git a/testData/ApiCreator/src/WildCardImports_after.java b/testData/ApiCreator/src/WildCardImports_after.java
index 16c5311..5856139 100644
--- a/testData/ApiCreator/src/WildCardImports_after.java
+++ b/testData/ApiCreator/src/WildCardImports_after.java
@@ -1,11 +1,9 @@
 package com.example.creation;
 
 import android.app.Activity;
-import android.net.Uri;
-import android.os.Bundle;
 
-import com.google.android.gms.appindexing.*;
-import com.google.android.gms.common.api.*;
+import com.google.firebase.appindexing.*;
+import com.google.firebase.appindexing.builders.Actions;
 
 public class MainActivity extends Activity {
 
@@ -13,30 +11,8 @@
    * ATTENTION: This was auto-generated to implement the App Indexing API.
    * See https://g.co/AppIndexing/AndroidStudio for more information.
    */
-  private GoogleApiClient client;
-
-  @Override
-  protected void onCreate(Bundle savedInstanceState) {
-    super.onCreate(savedInstanceState);
-    // ATTENTION: This was auto-generated to implement the App Indexing API.
-    // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
-  }
-
-  /**
-   * ATTENTION: This was auto-generated to implement the App Indexing API.
-   * See https://g.co/AppIndexing/AndroidStudio for more information.
-   */
   public Action getIndexApiAction() {
-    Thing object = new Thing.Builder()
-      .setName("Main Page") // TODO: Define a title for the content shown.
-      // TODO: Make sure this auto-generated URL is correct.
-      .setUrl(Uri.parse("http://www.example.com/main"))
-      .build();
-    return new Action.Builder(Action.TYPE_VIEW)
-      .setObject(object)
-      .setActionStatus(Action.STATUS_TYPE_COMPLETED)
-      .build();
+    return Actions.newView("Main", "http://www.example.com/main");
   }
 
   @Override
@@ -45,17 +21,14 @@
 
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    client.connect();
-    AppIndex.AppIndexApi.start(client, getIndexApiAction());
+    FirebaseUserActions.getInstance().start(getIndexApiAction());
   }
 
   @Override
   public void onStop() {
-    super.onStop();
-
     // ATTENTION: This was auto-generated to implement the App Indexing API.
     // See https://g.co/AppIndexing/AndroidStudio for more information.
-    AppIndex.AppIndexApi.end(client, getIndexApiAction());
-    client.disconnect();
+    FirebaseUserActions.getInstance().end(getIndexApiAction());
+    super.onStop();
   }
-}
+}
\ No newline at end of file
diff --git a/testSrc/com/google/appindexing/api/ApiCreatorTest.java b/testSrc/com/google/appindexing/api/ApiCreatorTest.java
index 989ee79..d556720 100644
--- a/testSrc/com/google/appindexing/api/ApiCreatorTest.java
+++ b/testSrc/com/google/appindexing/api/ApiCreatorTest.java
@@ -17,7 +17,6 @@
 
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Splitter;
-
 import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.PathManager;
@@ -27,29 +26,17 @@
 import com.intellij.psi.PsiManager;
 import com.intellij.psi.codeStyle.CodeStyleSettings;
 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
-import com.intellij.psi.xml.XmlFile;
 import org.jetbrains.android.AndroidTestCase;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 public class ApiCreatorTest extends AndroidTestCase {
   private static final String BASE_PATH = PathManager.getHomePath() + "/../studio/google/appindexing/testData/ApiCreator";
 
   private static final String ANDROID_MANIFEST = "AndroidManifest.xml";
-  private static final String ANDROID_MANIFEST_AFTER = "AndroidManifest_after.xml";
-  private static final String ANDROID_MANIFEST_HAS_GMS_TAG = "has_gms_tag.xml";
-  private static final String BUILD_GRADLE = "build.gradle";
-  private static final String BUILD_GRADLE_AFTER = "build_after.gradle";
-  private static final String BUILD_GRADLE_HAS_APP_INDEXING_DEPENDENCY = "has_app_indexing_dependency.gradle";
-  private static final String BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY = "low_version_app_indexing_dependency.gradle";
-  private static final String BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY_AFTER = "low_version_app_indexing_dependency_after.gradle";
-  private static final String BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY = "low_version_play_services_dependency.gradle";
-  private static final String BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY_AFTER = "low_version_play_services_dependency_after.gradle";
   private static final String CARET_NOT_IN_JAVA_FILE = "caret_not_in_java_file.xml";
   private static final String JAVA_FILE_CARET_OUTSIDE_ACTIVITY = "src/CaretOutsideActivity.java";
   private static final String JAVA_FILE_NOT_ACTIVITY = "src/NotActivity.java";
   private static final String JAVA_FILE_HAS_APP_INDEXING_START_AND_END = "src/HasAppIndexingStartAndEnd.java";
-  private static final String JAVA_FILE_HAS_APP_INDEXING_VIEW_AND_VIEW_END = "src/HasAppIndexingViewAndViewEnd.java";
   private static final String JAVA_FILE_SPECIAL_STATEMENT = "src/SpecialStatement.java";
   private static final String JAVA_FILE_EMPTY_ACTIVITY = "src/EmptyActivity.java";
   private static final String JAVA_FILE_EMPTY_ACTIVITY_AFTER = "src/EmptyActivity_after.java";
@@ -57,34 +44,16 @@
   private static final String JAVA_FILE_CONFLICT_IMPORTS_AFTER = "src/ConflictImports_after.java";
   private static final String JAVA_FILE_WILD_CARD_IMPORTS = "src/WildCardImports.java";
   private static final String JAVA_FILE_WILD_CARD_IMPORTS_AFTER = "src/WildCardImports_after.java";
-  private static final String JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER =
-    "src/OnlyStartCallAndAdjustClientFieldInitializer.java";
-  private static final String JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER_AFTER =
-    "src/OnlyStartCallAndAdjustClientFieldInitializer_after.java";
-  private static final String JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT =
-    "src/OnlyEndCallAndAdjustClientInitializingStatement.java";
-  private static final String JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT_AFTER =
-    "src/OnlyEndCallAndAdjustClientInitializingStatement_after.java";
-  private static final String JAVA_FILE_ONLY_VIEW_CALL = "src/OnlyViewCall.java";
-  private static final String JAVA_FILE_ONLY_VIEW_CALL_AFTER = "src/OnlyViewCall_after.java";
-  private static final String JAVA_FILE_ONLY_VIEW_END_CALL = "src/OnlyViewEndCall.java";
-  private static final String JAVA_FILE_ONLY_VIEW_END_CALL_AFTER = "src/OnlyViewEndCall_after.java";
-  private static final String JAVA_FILE_ACTION_NOT_INITIALIZED = "src/ActionNotInitialized.java";
-  private static final String JAVA_FILE_ACTION_NOT_INITIALIZED_AFTER = "src/ActionNotInitialized_after.java";
-  private static final String JAVA_FILE_CLIENT_FIELD = "src/ClientField.java";
-  private static final String JAVA_FILE_CLIENT_FIELD_AFTER = "src/ClientField_after.java";
-  private static final String JAVA_FILE_CLIENT_LOCAL_VARIABLE = "src/ClientLocalVariable.java";
-  private static final String JAVA_FILE_CLIENT_LOCAL_VARIABLE_FIELD_AFTER = "src/ClientLocalVariable_after.java";
-  private static final String JAVA_FILE_CLIENT_NOT_INITIALIZED = "src/ClientNotInitialized.java";
-  private static final String JAVA_FILE_CLIENT_NOT_INITIALIZED_AFTER = "src/ClientNotInitialized_after.java";
-  private static final String JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER = "src/ClientInitializedWithoutBuilder.java";
-  private static final String JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER_AFTER = "src/ClientInitializedWithoutBuilder_after.java";
-  private static final String JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT = "src/ClientInDeclarationStatement.java";
-  private static final String JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT_AFTER = "src/ClientInDeclarationStatement_after.java";
+  private static final String JAVA_FILE_ONLY_START_CALL = "src/OnlyStartCall.java";
+  private static final String JAVA_FILE_ONLY_START_CALL_AFTER = "src/OnlyStartCall_after.java";
+  private static final String JAVA_FILE_ONLY_END_CALL = "src/OnlyEndCall.java";
+  private static final String JAVA_FILE_ONLY_END_CALL_AFTER = "src/OnlyEndCall_after.java";
   private static final String JAVA_FILE_OVERRIDE_METHOD = "src/OverrideMethod.java";
   private static final String JAVA_FILE_OVERRIDE_METHOD_AFTER = "src/OverrideMethod_after.java";
   private static final String JAVA_FILE_NO_KEYWORD_SUPER = "src/NoKeywordSuper.java";
   private static final String JAVA_FILE_NO_KEYWORD_SUPER_AFTER = "src/NoKeywordSuper_after.java";
+  private static final String JAVA_FILE_CONFLICT_METHOD_NAME = "src/ConflictGetActionMethodName.java";
+  private static final String JAVA_FILE_CONFLICT_METHOD_NAME_AFTER = "src/ConflictGetActionMethodName_after.java";
 
   @Override
   protected boolean providesCustomManifest() {
@@ -108,33 +77,6 @@
     CodeStyleSettingsManager.getInstance().dropTemporarySettings();
   }
 
-  public void testNoAppIndexingDependencyInGradle() throws Exception {
-    doGradleFileTest(BUILD_GRADLE, BUILD_GRADLE_AFTER, null, true);
-  }
-
-  public void testHasAppIndexingDependencyInGradle() throws Exception {
-    doGradleFileTest(BUILD_GRADLE_HAS_APP_INDEXING_DEPENDENCY, BUILD_GRADLE_AFTER, "8.4.0", false);
-  }
-
-  public void testLowVersionAppIndexingDependencyInGradle() throws Exception {
-    doGradleFileTest(BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY, BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY_AFTER, "6.5.0",
-                     true);
-  }
-
-  public void testLowVersionPlayServicesDependencyInGradle() throws Exception {
-    doGradleFileTest(BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY, BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY_AFTER, "6.5.0",
-                     true);
-  }
-
-
-  public void testNoGmsTagInAndroidManifest() throws Exception {
-    doManifestFileTest(ANDROID_MANIFEST, ANDROID_MANIFEST_AFTER);
-  }
-
-  public void testHasGmsTagInAndroidManifest() throws Exception {
-    doManifestFileTest(ANDROID_MANIFEST_HAS_GMS_TAG, ANDROID_MANIFEST_AFTER);
-  }
-
   public void testCaretInAndroidManifest() throws Exception {
     doEnableTest(CARET_NOT_IN_JAVA_FILE, false);
   }
@@ -151,10 +93,6 @@
     doEnableTest(JAVA_FILE_HAS_APP_INDEXING_START_AND_END, false);
   }
 
-  public void testHasAppIndexingApiViewAndViewEnd() throws Exception {
-    doEnableTest(JAVA_FILE_HAS_APP_INDEXING_VIEW_AND_VIEW_END, false);
-  }
-
   /**
    * The app indexing APIs are used in special statements,
    * such as block statements, declaration statements and loop statement.
@@ -163,7 +101,6 @@
     doEnableTest(JAVA_FILE_SPECIAL_STATEMENT, false);
   }
 
-
   public void testEmptyActivity() throws Exception {
     doJavaFileTest(JAVA_FILE_EMPTY_ACTIVITY, JAVA_FILE_EMPTY_ACTIVITY_AFTER);
   }
@@ -176,46 +113,12 @@
     doJavaFileTest(JAVA_FILE_WILD_CARD_IMPORTS, JAVA_FILE_WILD_CARD_IMPORTS_AFTER);
   }
 
-  public void testOnlyAppIndexingStartAndAdjustGoogleApiClientFieldInitializer() throws Exception {
-    doJavaFileTest(JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER,
-                   JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER_AFTER);
+  public void testOnlyAppIndexingStart() throws Exception {
+    doJavaFileTest(JAVA_FILE_ONLY_START_CALL, JAVA_FILE_ONLY_START_CALL_AFTER);
   }
 
-  public void testOnlyAppIndexingEndAndAdjustClientInitializingStatement() throws Exception {
-    doJavaFileTest(JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT,
-                   JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT_AFTER);
-  }
-
-  public void testOnlyAppIndexingView() throws Exception {
-    doJavaFileTest(JAVA_FILE_ONLY_VIEW_CALL, JAVA_FILE_ONLY_VIEW_CALL_AFTER);
-  }
-
-  public void testOnlyAppIndexingViewEnd() throws Exception {
-    doJavaFileTest(JAVA_FILE_ONLY_VIEW_END_CALL, JAVA_FILE_ONLY_VIEW_END_CALL_AFTER);
-  }
-
-  public void testGoogleApiActionNotInitialized() throws Exception {
-    doJavaFileTest(JAVA_FILE_ACTION_NOT_INITIALIZED, JAVA_FILE_ACTION_NOT_INITIALIZED_AFTER);
-  }
-
-  public void testWithGoogleApiClientField() throws Exception {
-    doJavaFileTest(JAVA_FILE_CLIENT_FIELD, JAVA_FILE_CLIENT_FIELD_AFTER);
-  }
-
-  public void testWithGoogleApiClientLocalVariable() throws Exception {
-    doJavaFileTest(JAVA_FILE_CLIENT_LOCAL_VARIABLE, JAVA_FILE_CLIENT_LOCAL_VARIABLE_FIELD_AFTER);
-  }
-
-  public void testGoogleApiClientNotInitialized() throws Exception {
-    doJavaFileTest(JAVA_FILE_CLIENT_NOT_INITIALIZED, JAVA_FILE_CLIENT_NOT_INITIALIZED_AFTER);
-  }
-
-  public void testGoogleApiClientInitializedWithoutBuilder() throws Exception {
-    doJavaFileTest(JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER, JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER_AFTER);
-  }
-
-  public void testGetGoogleApiClientFromDeclarationStatement() throws Exception {
-    doJavaFileTest(JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT, JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT_AFTER);
+  public void testOnlyAppIndexingEnd() throws Exception {
+    doJavaFileTest(JAVA_FILE_ONLY_END_CALL, JAVA_FILE_ONLY_END_CALL_AFTER);
   }
 
   public void testWithOverridingMethod() throws Exception {
@@ -230,6 +133,13 @@
   }
 
   /**
+   * Tests class with conflicted method name.
+   */
+  public void testConflictMethodName() throws Exception {
+    doJavaFileTest(JAVA_FILE_CONFLICT_METHOD_NAME, JAVA_FILE_CONFLICT_METHOD_NAME_AFTER);
+  }
+
+  /**
    * Tests whether the project is eligible for App Indexing API code inserting.
    *
    * @param filePath The path of the Java source file.
@@ -244,7 +154,7 @@
    * Test for creation in Java source file.
    */
   private void doJavaFileTest(@NotNull String testFilePath, @NotNull String expectedFilePath) {
-    doEnableTest(testFilePath, true);
+    myFixture.configureByFiles(testFilePath);
     myFixture.copyFileToProject(ANDROID_MANIFEST);
     final ApiCreator creator = new ApiCreator(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
     CommandProcessor.getInstance().executeCommand(null, new Runnable() {
@@ -253,11 +163,12 @@
         ApplicationManager.getApplication().runWriteAction(new Runnable() {
           @Override
           public void run() {
-            creator.insertAppIndexingApiCodeInJavaFile(creator.getDeepLinkOfActivity(), false);
+            creator.insertAppIndexingApiCodeInJavaFile(creator.getDeepLinkOfActivity());
           }
         });
       }
     }, null, null);
+
     VirtualFile expectedFile = myFixture.copyFileToProject(expectedFilePath);
     PsiFile expectedPsiFile = PsiManager.getInstance(myFixture.getProject()).findFile(expectedFile);
     assertNotNull(expectedPsiFile);
@@ -265,62 +176,6 @@
     assertEquals(normalizedTestFile, getNormalizedContent(expectedPsiFile));
   }
 
-  /**
-   * Test for creation in build.gradle file.
-   */
-  private void doGradleFileTest(@NotNull String testFilePath,
-                                @NotNull String expectedFilePath,
-                                @Nullable final String version,
-                                final boolean needSync) {
-    VirtualFile testVirtual = myFixture.copyFileToProject(testFilePath, getGradleRelativePath());
-    myFixture.configureByFile(JAVA_FILE_EMPTY_ACTIVITY); // This file is not used. It's for opening editor.
-
-    final ApiCreator creator = new ApiCreator(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
-    creator.setGmsLibVersion(version);
-    CommandProcessor.getInstance().executeCommand(null, new Runnable() {
-      @Override
-      public void run() {
-        ApplicationManager.getApplication().runWriteAction(new Runnable() {
-          @Override
-          public void run() {
-            try {
-              assertEquals(creator.insertGmsCompileDependencyInGradleIfNeeded(), needSync);
-            }
-            catch (ApiCreator.ApiCreatorException e) {
-              e.printStackTrace();
-              fail();
-            }
-          }
-        });
-      }
-    }, null, null);
-
-    PsiFile testPsi = PsiManager.getInstance(myFixture.getProject()).findFile(testVirtual);
-    PsiFile expectedPsi = myFixture.configureByFile(expectedFilePath);
-    assertNotNull(testPsi);
-    assertEquals(getNormalizedContent(testPsi), getNormalizedContent(expectedPsi));
-  }
-
-  /**
-   * Test for creation in AndroidManifest.xml file.
-   */
-  private void doManifestFileTest(@NotNull String testFilePath, @NotNull String expectedFilePath) {
-    PsiFile[] files = myFixture.configureByFiles(testFilePath, expectedFilePath);
-    final ApiCreator creator = new ApiCreator(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
-    CommandProcessor.getInstance().executeCommand(null, new Runnable() {
-      @Override
-      public void run() {
-        ApplicationManager.getApplication().runWriteAction(new Runnable() {
-          @Override
-          public void run() {
-            assertTrue(myFixture.getFile() instanceof XmlFile);
-            creator.insertGmsVersionTagInManifestIfNeeded((XmlFile)myFixture.getFile());
-          }
-        });
-      }
-    }, null, null);
-    assertEquals(getNormalizedContent(myFixture.getFile()), getNormalizedContent(files[1]));
-  }
 
   /**
    * Normalizes file content: remove java.lang imports, comments, white space and line terminators.