Search in sources :

Example 1 with ApkProvisionException

use of com.android.tools.idea.run.ApkProvisionException in project intellij by bazelbuild.

the class BlazeAndroidBinaryApplicationIdProvider method getPackageName.

@Override
public String getPackageName() throws ApkProvisionException {
    BlazeAndroidDeployInfo deployInfo = buildStep.getDeployInfo();
    Manifest manifest = deployInfo.getMergedManifest();
    if (manifest == null) {
        throw new ApkProvisionException("Could not find merged manifest: " + deployInfo.getMergedManifestFile());
    }
    String applicationId = ApplicationManager.getApplication().runReadAction((Computable<String>) () -> manifest.getPackage().getValue());
    if (applicationId == null) {
        throw new ApkProvisionException("No application id in merged manifest: " + deployInfo.getMergedManifestFile());
    }
    return applicationId;
}
Also used : ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Manifest(org.jetbrains.android.dom.manifest.Manifest)

Example 2 with ApkProvisionException

use of com.android.tools.idea.run.ApkProvisionException in project intellij by bazelbuild.

the class BlazeAndroidBinaryApplicationLaunchTaskProvider method getApplicationLaunchTask.

public static LaunchTask getApplicationLaunchTask(Project project, ApplicationIdProvider applicationIdProvider, File mergedManifestFile, BlazeAndroidBinaryRunConfigurationState configState, StartActivityFlagsProvider startActivityFlagsProvider, ProcessHandlerLaunchStatus processHandlerLaunchStatus) {
    try {
        String applicationId = applicationIdProvider.getPackageName();
        final LaunchTask launchTask;
        switch(configState.getMode()) {
            case BlazeAndroidBinaryRunConfigurationState.DO_NOTHING:
                launchTask = null;
                break;
            case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEFAULT_ACTIVITY:
                BlazeDefaultActivityLocator activityLocator = new BlazeDefaultActivityLocator(project, mergedManifestFile);
                launchTask = new DefaultActivityLaunchTask(applicationId, activityLocator, startActivityFlagsProvider);
                break;
            case BlazeAndroidBinaryRunConfigurationState.LAUNCH_SPECIFIC_ACTIVITY:
                launchTask = new SpecificActivityLaunchTask(applicationId, configState.getActivityClass(), startActivityFlagsProvider);
                break;
            case BlazeAndroidBinaryRunConfigurationState.LAUNCH_DEEP_LINK:
                launchTask = new AndroidDeepLinkLaunchTask(configState.getDeepLink(), startActivityFlagsProvider);
                break;
            default:
                launchTask = null;
                break;
        }
        return launchTask;
    } catch (ApkProvisionException e) {
        LOG.error(e);
        processHandlerLaunchStatus.terminateLaunch("Unable to identify application id");
        return null;
    }
}
Also used : SpecificActivityLaunchTask(com.android.tools.idea.run.tasks.SpecificActivityLaunchTask) DefaultActivityLaunchTask(com.android.tools.idea.run.tasks.DefaultActivityLaunchTask) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) SpecificActivityLaunchTask(com.android.tools.idea.run.tasks.SpecificActivityLaunchTask) LaunchTask(com.android.tools.idea.run.tasks.LaunchTask) DefaultActivityLaunchTask(com.android.tools.idea.run.tasks.DefaultActivityLaunchTask) AndroidDeepLinkLaunchTask(com.android.tools.idea.run.tasks.AndroidDeepLinkLaunchTask) AndroidDeepLinkLaunchTask(com.android.tools.idea.run.tasks.AndroidDeepLinkLaunchTask)

Example 3 with ApkProvisionException

use of com.android.tools.idea.run.ApkProvisionException in project intellij by bazelbuild.

the class BlazeAndroidBinaryNormalBuildRunContext method getApplicationLaunchTask.

@Override
public LaunchTask getApplicationLaunchTask(LaunchOptions launchOptions, @Nullable Integer userId, AndroidDebugger androidDebugger, AndroidDebuggerState androidDebuggerState, ProcessHandlerLaunchStatus processHandlerLaunchStatus) throws ExecutionException {
    final StartActivityFlagsProvider startActivityFlagsProvider = new DefaultStartActivityFlagsProvider(androidDebugger, androidDebuggerState, project, launchOptions.isDebug(), UserIdHelper.getFlagsFromUserId(userId));
    BlazeAndroidDeployInfo deployInfo;
    try {
        deployInfo = buildStep.getDeployInfo();
    } catch (ApkProvisionException e) {
        throw new ExecutionException(e);
    }
    return BlazeAndroidBinaryApplicationLaunchTaskProvider.getApplicationLaunchTask(project, applicationIdProvider, deployInfo.getMergedManifestFile(), configState, startActivityFlagsProvider, processHandlerLaunchStatus);
}
Also used : DefaultStartActivityFlagsProvider(com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) StartActivityFlagsProvider(com.android.tools.idea.run.activity.StartActivityFlagsProvider) DefaultStartActivityFlagsProvider(com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider) ExecutionException(com.intellij.execution.ExecutionException)

Example 4 with ApkProvisionException

use of com.android.tools.idea.run.ApkProvisionException in project intellij by bazelbuild.

the class BlazeAndroidLaunchTasksProvider method getConnectDebuggerTask.

@Nullable
@Override
public DebugConnectorTask getConnectDebuggerTask(@NotNull LaunchStatus launchStatus, @Nullable AndroidVersion version) {
    if (!isDebug) {
        return null;
    }
    Set<String> packageIds = Sets.newHashSet();
    try {
        String packageName = applicationIdProvider.getPackageName();
        packageIds.add(packageName);
    } catch (ApkProvisionException e) {
        Logger.getInstance(AndroidLaunchTasksProvider.class).error(e);
    }
    try {
        String packageName = applicationIdProvider.getTestPackageName();
        if (packageName != null) {
            packageIds.add(packageName);
        }
    } catch (ApkProvisionException e) {
        // not as severe as failing to obtain package id for main application
        Logger.getInstance(AndroidLaunchTasksProvider.class).warn("Unable to obtain test package name, will not connect debugger " + "if tests don't instantiate main application");
    }
    AndroidDebugger androidDebugger = debuggerManager.getAndroidDebugger();
    AndroidDebuggerState androidDebuggerState = debuggerManager.getAndroidDebuggerState(project);
    if (androidDebugger == null || androidDebuggerState == null) {
        return null;
    }
    try {
        return runContext.getDebuggerTask(androidDebugger, androidDebuggerState, packageIds, monitorRemoteProcess());
    } catch (ExecutionException e) {
        launchStatus.terminateLaunch(e.getMessage());
        return null;
    }
}
Also used : AndroidDebugger(com.android.tools.idea.run.editor.AndroidDebugger) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) AndroidDebuggerState(com.android.tools.idea.run.editor.AndroidDebuggerState) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ApkProvisionException

use of com.android.tools.idea.run.ApkProvisionException in project intellij by bazelbuild.

the class BlazeAndroidTestApplicationIdProvider method getPackageName.

@Override
public String getPackageName() throws ApkProvisionException {
    BlazeAndroidDeployInfo deployInfo = buildStep.getDeployInfo();
    Manifest manifest = Iterables.getFirst(deployInfo.getAdditionalMergedManifests(), null);
    if (manifest == null) {
        // and can instead be in the same package as the tests.
        return getTestPackageName();
    }
    String applicationId = ApplicationManager.getApplication().runReadAction((Computable<String>) () -> manifest.getPackage().getValue());
    if (applicationId == null) {
        throw new ApkProvisionException("No application id in manifest under test");
    }
    return applicationId;
}
Also used : ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Manifest(org.jetbrains.android.dom.manifest.Manifest)

Aggregations

ApkProvisionException (com.android.tools.idea.run.ApkProvisionException)9 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)5 ExecutionException (com.intellij.execution.ExecutionException)4 Manifest (org.jetbrains.android.dom.manifest.Manifest)3 DefaultStartActivityFlagsProvider (com.android.tools.idea.run.activity.DefaultStartActivityFlagsProvider)2 StartActivityFlagsProvider (com.android.tools.idea.run.activity.StartActivityFlagsProvider)2 AndroidDebuggerState (com.android.tools.idea.run.editor.AndroidDebuggerState)2 LaunchTask (com.android.tools.idea.run.tasks.LaunchTask)2 LaunchOptions (com.android.tools.idea.run.LaunchOptions)1 AndroidDebugger (com.android.tools.idea.run.editor.AndroidDebugger)1 AndroidDeepLinkLaunchTask (com.android.tools.idea.run.tasks.AndroidDeepLinkLaunchTask)1 ClearLogcatTask (com.android.tools.idea.run.tasks.ClearLogcatTask)1 DefaultActivityLaunchTask (com.android.tools.idea.run.tasks.DefaultActivityLaunchTask)1 DismissKeyguardTask (com.android.tools.idea.run.tasks.DismissKeyguardTask)1 ShowLogcatTask (com.android.tools.idea.run.tasks.ShowLogcatTask)1 SpecificActivityLaunchTask (com.android.tools.idea.run.tasks.SpecificActivityLaunchTask)1 ProcessHandlerLaunchStatus (com.android.tools.idea.run.util.ProcessHandlerLaunchStatus)1 AndroidNativeAttachConfiguration (com.android.tools.ndk.run.attach.AndroidNativeAttachConfiguration)1 NativeAndroidDebuggerState (com.android.tools.ndk.run.editor.NativeAndroidDebuggerState)1 BlazeAndroidNativeAttachConfigurationFactory (com.google.idea.blaze.android.run.attach.BlazeAndroidNativeAttachConfigurationFactory)1