public void createMockableJarTask() { createMockableJar = project.getTasks().create("mockableAndroidJar", MockableAndroidJarTask.class); createMockableJar.setGroup(BUILD_GROUP); createMockableJar.setDescription( "Creates a version of android.jar that's suitable for unit tests."); ConventionMappingHelper.map(createMockableJar, "androidJar", new Callable<File>() { @Override public File call() throws Exception { return new File(androidBuilder.getTarget().getPath(IAndroidTarget.ANDROID_JAR)); } }); CharMatcher safeCharacters = CharMatcher.JAVA_LETTER_OR_DIGIT.or(CharMatcher.anyOf("-.")); String sdkName = safeCharacters.negate().replaceFrom(extension.getCompileSdkVersion(), '-'); createMockableJar.setOutputFile( new File(globalScope.getIntermediatesDir(), "mockable-" + sdkName + ".jar")); ConventionMappingHelper.map(createMockableJar, "returnDefaultValues", new Callable<Boolean>() { @Override public Boolean call() { return extension.getTestOptions().getUnitTests().isReturnDefaultValues(); } }); }
@NonNull public File getMockableAndroidJarFile() { if (mockableAndroidJarFile == null) { // Since the file ends up in $rootProject.buildDir, it will survive clean // operations - projects generated by AS don't have a top-level clean task that // would delete the top-level build directory. This means that the name has to // encode all the necessary information, otherwise the task will be UP-TO-DATE // even if the file should be regenerated. That's why we put the SDK version and // "default-values" in there, so if one project uses the returnDefaultValues flag, // it will just generate a new file and not change the semantics for other // sub-projects. There's an implicit "v1" there as well, if we ever change the // generator logic, the names will have to be changed. String fileExt; if (getExtension().getTestOptions().getUnitTests().isReturnDefaultValues()) { fileExt = ".default-values.jar"; } else { fileExt = ".jar"; } File outDir = new File( getProject().getRootProject().getBuildDir(), AndroidProject.FD_GENERATED); CharMatcher safeCharacters = CharMatcher.JAVA_LETTER_OR_DIGIT.or(CharMatcher.anyOf("-.")); String sdkName = safeCharacters.negate().replaceFrom( getExtension().getCompileSdkVersion(), '-'); mockableAndroidJarFile = new File(outDir, "mockable-" + sdkName + fileExt); } return mockableAndroidJarFile; }
final BaseVariantData testedVariantData = scope.getTestedVariantData(); scope.getVariantData().javacTask = javacTask; javacTask.compileSdkVersion = scope.getGlobalScope().getExtension().getCompileSdkVersion(); javacTask.mBuildContext = scope.getInstantRunBuildContext(); javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion(), scope.getVariantConfiguration().getJackOptions().isEnabled());
javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion() );
@Override public void execute(@NonNull AndroidJavaCompile javacTask) { javacTask.compileSdkVersion = scope.getGlobalScope().getExtension().getCompileSdkVersion(); javacTask.mBuildContext = scope.getInstantRunBuildContext(); javacTask.source(scope.getRClassSourceOutputDir(atomDependency)); javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion(), scope.getVariantConfiguration().getJackOptions().isEnabled());
scope.getGlobalScope().getExtension().getCompileSdkVersion(), true /*jackEnabled*/); options.setSourceCompatibility(compileOptions.getSourceCompatibility().toString());
jackTask, scope.getGlobalScope().getExtension().getCompileOptions(), scope.getGlobalScope().getExtension().getCompileSdkVersion() );