Android Studio 3.5及更高版本中弃用了'AndroidModuleModel.findProductFlavor”方法,而是使用'AndroidModuleModel.getProductFlavors()”方法。下面是一个使用新方法的代码示例:
import com.android.build.gradle.api.AndroidSourceSet;
import com.android.build.gradle.api.ProductFlavor;
import com.android.build.gradle.internal.dsl.ProductFlavorImpl;
import com.android.build.gradle.internal.scope.VariantScopeImpl;
import com.android.build.gradle.tasks.AidlCompile;
import com.android.build.gradle.tasks.ExternalNativeBuildTask;
import com.android.build.gradle.tasks.JavaCompile;
import com.android.build.gradle.tasks.MergeResources;
import com.android.build.gradle.tasks.NdkCompile;
import com.android.build.gradle.tasks.RenderscriptCompile;
import com.android.build.gradle.tasks.ShaderCompile;
import com.android.build.gradle.tasks.TestCompile;
import com.android.builder.model.AndroidLibrary;
import com.android.builder.model.AndroidProject;
import com.android.builder.model.JavaLibrary;
import com.android.builder.model.AndroidArtifact;
import com.android.builder.model.AndroidArtifactOutput;
import com.android.builder.model.AndroidArtifactVariant;
import com.android.builder.model.AndroidFactory;
import com.android.builder.model.AndroidProject;
import com.android.builder.model.BuildType;
import com.android.builder.model.LintOptions;
import com.android.builder.model.MultiOutputPolicy;
import com.android.builder.model.ProductFlavor;
import com.android.builder.model.ProjectSyncIssues;
import com.android.builder.model.SigningConfig;
import com.android.builder.model.SourceProvider;
import com.android.builder.model.Variant;
import com.android.builder.model.VariantBuildInformation;
import com.android.builder.model.VariantBuildOutput;
import com.android.builder.model.Version;
import com.android.builder.model.level2.DependencyGraphs;
import com.android.builder.model.level2.GlobalLibraryMap;
import com.android.builder.model.level2.Library;
import com.android.builder.model.level2.LibraryType;
import com.android.builder.model.level2.LocalLibrary;
import com.android.builder.model.level2.LocalLibraryBuildService;
import com.android.builder.model.level2.ModuleDependencies;
import com.android.builder.model.level2.ProjectBuildOutput;
import com.android.builder.model.level2.ResolvedDependency;
import com.android.ide.common.gradle.model.IdeAndroidProject;
import com.android.ide.common.gradle.model.IdeVariant;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.attributes.Usage;
import org.gradle.api.file.FileCollection;
import org.gradle.api.logging.Logger;
import org.gradle