com.android.build.gradle.LibraryExtension Java Examples

The following examples show how to use com.android.build.gradle.LibraryExtension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InjectorPlugin.java    From Injector with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(@NotNull Project target) {
	this.project = target;
	createExtension();
	createConfiguration();
	createExtractAARsTask();
	target.afterEvaluate(project1 -> {
		System.out.println("After evaluate");
		resolveArtifacts();
		if (jars.isEmpty() && aars.isEmpty()) {
			return;
		}
		Utils.removeOldArtifacts(jars);
		Utils.removeOldArtifacts(aars);

		Object extension = project1.getExtensions().getByName("android");
		if (extension instanceof LibraryExtension) {
			((LibraryExtension) extension).getLibraryVariants().all(this::processVariant);
		} else if (extension instanceof AppExtension) {
			((AppExtension) extension).getApplicationVariants().all(this::processVariant);
		}
	});
}
 
Example #2
Source File: SdkUtil.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
public static File getAndroidJar(Project project) {
  LibraryExtension android = project.getExtensions().findByType(LibraryExtension.class);
  if (android == null) {
    throw new GradleException("Project " + project.getPath() + " is not an android library.");
  }
  return new File(
      getSdkDir(project),
      String.format("/platforms/%s/android.jar", android.getCompileSdkVersion()));
}
 
Example #3
Source File: AtlasLibTaskManager.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasLibTaskManager(AtlasBuilder androidBuilder,
                           LibraryExtension libraryExtension,
                           Project project,
                           AtlasExtension atlasExtension) {
    super(androidBuilder, libraryExtension, project, atlasExtension);
    this.libraryExtension = libraryExtension;
}
 
Example #4
Source File: FirebaseLibraryPlugin.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(Project project) {
  project.apply(ImmutableMap.of("plugin", "com.android.library"));

  FirebaseLibraryExtension firebaseLibrary =
      project
          .getExtensions()
          .create(
              "firebaseLibrary", FirebaseLibraryExtension.class, project, LibraryType.ANDROID);

  LibraryExtension android = project.getExtensions().getByType(LibraryExtension.class);

  // In the case of and android library signing config only affects instrumentation test APK.
  // We need it signed with default debug credentials in order for FTL to accept the APK.
  android.buildTypes(
      types ->
          types
              .getByName("release")
              .setSigningConfig(types.getByName("debug").getSigningConfig()));

  // see https://github.com/robolectric/robolectric/issues/5456
  android.testOptions(
      options ->
          options
              .getUnitTests()
              .all(
                  closureOf(
                      test -> {
                        test.systemProperty("robolectric.dependency.repo.id", "central");
                        test.systemProperty(
                            "robolectric.dependency.repo.url", "https://repo1.maven.org/maven2");
                        test.systemProperty("javax.net.ssl.trustStoreType", "JKS");
                      })));

  // skip debug tests in CI
  // TODO(vkryachko): provide ability for teams to control this if needed
  if (System.getenv().containsKey("FIREBASE_CI")) {
    android.setTestBuildType("release");
    project
        .getTasks()
        .all(
            task -> {
              if ("testDebugUnitTest".equals(task.getName())) {
                task.setEnabled(false);
              }
            });
  }

  setupApiInformationAnalysis(project, android);

  android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab));

  setupStaticAnalysis(project, firebaseLibrary);

  // reduce the likelihood of kotlin module files colliding.
  project
      .getTasks()
      .withType(
          KotlinCompile.class,
          kotlin ->
              kotlin
                  .getKotlinOptions()
                  .setFreeCompilerArgs(
                      ImmutableList.of("-module-name", kotlinModuleName(project))));

  project.afterEvaluate(p -> Dokka.configure(project, android, firebaseLibrary));
}
 
Example #5
Source File: FirebaseLibraryPlugin.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {
  File metalavaOutputJarFile = new File(project.getRootProject().getBuildDir(), "metalava.jar");
  AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main");
  File outputFile =
      project
          .getRootProject()
          .file(
              Paths.get(
                  project.getRootProject().getBuildDir().getPath(),
                  "apiinfo",
                  project.getPath().substring(1).replace(":", "_")));
  File outputApiFile = new File(outputFile.getAbsolutePath() + "_api.txt");

  project
      .getTasks()
      .register(
          "getMetalavaJar",
          GetMetalavaJarTask.class,
          task -> {
            task.setOutputFile(metalavaOutputJarFile);
          });
  File apiTxt =
      project.file("api.txt").exists()
          ? project.file("api.txt")
          : project.file(project.getRootDir() + "/empty-api.txt");
  TaskProvider<ApiInformationTask> apiInfo =
      project
          .getTasks()
          .register(
              "apiInformation",
              ApiInformationTask.class,
              task -> {
                task.setApiTxt(apiTxt);
                task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
                task.setSourceSet(mainSourceSet);
                task.setOutputFile(outputFile);
                task.setBaselineFile(project.file("baseline.txt"));
                task.setOutputApiFile(outputApiFile);
                if (project.hasProperty("updateBaseline")) {
                  task.setUpdateBaseline(true);
                } else {
                  task.setUpdateBaseline(false);
                }
                task.dependsOn("getMetalavaJar");
              });

  TaskProvider<GenerateApiTxtFileTask> generateApiTxt =
      project
          .getTasks()
          .register(
              "generateApiTxtFile",
              GenerateApiTxtFileTask.class,
              task -> {
                task.setApiTxt(project.file("api.txt"));
                task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
                task.setSourceSet(mainSourceSet);
                task.setBaselineFile(project.file("baseline.txt"));
                task.setUpdateBaseline(project.hasProperty("updateBaseline"));
                task.dependsOn("getMetalavaJar");
              });

  TaskProvider<GenerateStubsTask> docStubs =
      project
          .getTasks()
          .register(
              "docStubs",
              GenerateStubsTask.class,
              task -> {
                task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
                task.setOutputDir(new File(project.getBuildDir(), "doc-stubs"));
                task.dependsOn("getMetalavaJar");

                task.setSourceSet(mainSourceSet);
              });
  project.getTasks().getByName("check").dependsOn(docStubs);

  android
      .getLibraryVariants()
      .all(
          v -> {
            if (v.getName().equals("release")) {
              FileCollection jars =
                  v.getCompileConfiguration()
                      .getIncoming()
                      .artifactView(
                          config ->
                              config.attributes(
                                  container ->
                                      container.attribute(
                                          Attribute.of("artifactType", String.class), "jar")))
                      .getArtifacts()
                      .getArtifactFiles();
              apiInfo.configure(t -> t.setClassPath(jars));
              generateApiTxt.configure(t -> t.setClassPath(jars));
              docStubs.configure(t -> t.setClassPath(jars));
            }
          });
}
 
Example #6
Source File: LibVariantContext.java    From atlas with Apache License 2.0 4 votes vote down vote up
public LibVariantContext(LibraryVariantImpl libraryVariant, Project project, @NonNull AtlasExtension atlasExtension,
                         LibraryExtension libraryExtension) {
    super(libraryVariant, project, atlasExtension, libraryExtension);
    this.variantData = (LibraryVariantData)baseVariantData;
}