android apklib,Java AndroidFacet.getConfiguration方法代码示例

import org.jetbrains.android.facet.AndroidFacet; //导入方法依赖的package包/类

@Nullable

private static Module importExternalApklibArtifact(Project project,

Module apklibModule,

IdeModifiableModelsProvider modelsProvider,

MavenProject mavenProject,

MavenProjectsTree mavenTree,

MavenId artifactMavenId,

String artifactFilePath,

ModifiableModuleModel moduleModel,

Map mavenProject2ModuleName) {

final String genModuleName = AndroidMavenUtil.getModuleNameForExtApklibArtifact(artifactMavenId);

String genExternalApklibsDirPath = null;

String targetDirPath = null;

if (apklibModule == null) {

genExternalApklibsDirPath =

AndroidMavenUtil.computePathForGenExternalApklibsDir(artifactMavenId, mavenProject, mavenTree.getProjects());

targetDirPath = genExternalApklibsDirPath != null

? genExternalApklibsDirPath + '/' + AndroidMavenUtil.getMavenIdStringForFileName(artifactMavenId)

: null;

}

else {

final VirtualFile[] contentRoots = ModuleRootManager.getInstance(apklibModule).getContentRoots();

if (contentRoots.length == 1) {

targetDirPath = contentRoots[0].getPath();

}

else {

final String moduleDir = new File(apklibModule.getModuleFilePath()).getParent();

if (moduleDir != null) {

targetDirPath = moduleDir + '/' + AndroidMavenUtil.getMavenIdStringForFileName(artifactMavenId);

}

}

}

if (targetDirPath == null) {

return null;

}

if (!extractArtifact(artifactFilePath, targetDirPath, project, genModuleName)){

return null;

}

final AndroidExternalApklibDependenciesManager adm = AndroidExternalApklibDependenciesManager.getInstance(project);

adm.setArtifactFilePath(artifactMavenId, FileUtil.toSystemIndependentName(artifactFilePath));

final VirtualFile vApklibDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(targetDirPath);

if (vApklibDir == null) {

LOG.error("Cannot find file " + targetDirPath + " in VFS");

return null;

}

if (apklibModule == null) {

final String genModuleFilePath = genExternalApklibsDirPath + '/' + genModuleName + ModuleFileType.DOT_DEFAULT_EXTENSION;

apklibModule = moduleModel.newModule(genModuleFilePath, StdModuleTypes.JAVA.getId());

}

final ModifiableRootModel apklibModuleModel = modelsProvider.getModifiableRootModel(apklibModule);

final ContentEntry contentEntry = apklibModuleModel.addContentEntry(vApklibDir);

final VirtualFile sourceRoot = vApklibDir.findChild(AndroidMavenUtil.APK_LIB_ARTIFACT_SOURCE_ROOT);

if (sourceRoot != null) {

contentEntry.addSourceFolder(sourceRoot, false);

}

final AndroidFacet facet = AndroidUtils.addAndroidFacet(apklibModuleModel.getModule(), vApklibDir, true);

final AndroidFacetConfiguration configuration = facet.getConfiguration();

String s = AndroidRootUtil.getPathRelativeToModuleDir(apklibModule, vApklibDir.getPath());

if (s != null) {

s = s.length() > 0 ? '/' + s + '/' : "/";

configuration.getState().RES_FOLDER_RELATIVE_PATH = s + AndroidMavenUtil.APK_LIB_ARTIFACT_RES_DIR;

configuration.getState().LIBS_FOLDER_RELATIVE_PATH = s + AndroidMavenUtil.APK_LIB_ARTIFACT_NATIVE_LIBS_DIR;

configuration.getState().MANIFEST_FILE_RELATIVE_PATH = s + AndroidMavenUtil.APK_LIB_ARTIFACT_MANIFEST_FILE;

}

importSdkAndDependenciesForApklibArtifact(project, apklibModuleModel, modelsProvider, mavenTree,

artifactMavenId, mavenProject2ModuleName);

return apklibModule;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值