Search in sources :

Example 6 with ApkProvisionException

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

the class BlazeAndroidTestApplicationIdProvider method getTestPackageName.

@Nullable
@Override
public String getTestPackageName() 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) Nullable(javax.annotation.Nullable)

Example 7 with ApkProvisionException

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

the class BlazeAndroidLaunchTasksProvider method getTasks.

@NotNull
@Override
public List<LaunchTask> getTasks(@NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter consolePrinter) throws ExecutionException {
    final List<LaunchTask> launchTasks = Lists.newArrayList();
    Integer userId = runContext.getUserId(device, consolePrinter);
    launchOptionsBuilder.setPmInstallOptions(UserIdHelper.getFlagsFromUserId(userId));
    LaunchOptions launchOptions = launchOptionsBuilder.build();
    if (launchOptions.isClearLogcatBeforeStart()) {
        launchTasks.add(new ClearLogcatTask(project));
    }
    launchTasks.add(new DismissKeyguardTask());
    if (launchOptions.isDeploy()) {
        ImmutableList<LaunchTask> deployTasks = runContext.getDeployTasks(device, launchOptions);
        launchTasks.addAll(deployTasks);
    }
    if (launchStatus.isLaunchTerminated()) {
        return launchTasks;
    }
    String packageName;
    try {
        packageName = applicationIdProvider.getPackageName();
        ProcessHandlerLaunchStatus processHandlerLaunchStatus = (ProcessHandlerLaunchStatus) launchStatus;
        LaunchTask appLaunchTask = runContext.getApplicationLaunchTask(launchOptions, userId, debuggerManager.getAndroidDebugger(), debuggerManager.getAndroidDebuggerState(project), processHandlerLaunchStatus);
        if (appLaunchTask != null) {
            launchTasks.add(appLaunchTask);
        }
    } catch (ApkProvisionException e) {
        LOG.error(e);
        launchStatus.terminateLaunch("Unable to determine application id: " + e);
        return ImmutableList.of();
    } catch (ExecutionException e) {
        launchStatus.terminateLaunch(e.getMessage());
        return ImmutableList.of();
    }
    if (!launchOptions.isDebug() && launchOptions.isOpenLogcatAutomatically()) {
        launchTasks.add(new ShowLogcatTask(project, packageName));
    }
    return launchTasks;
}
Also used : ShowLogcatTask(com.android.tools.idea.run.tasks.ShowLogcatTask) LaunchOptions(com.android.tools.idea.run.LaunchOptions) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) ClearLogcatTask(com.android.tools.idea.run.tasks.ClearLogcatTask) LaunchTask(com.android.tools.idea.run.tasks.LaunchTask) ExecutionException(com.intellij.execution.ExecutionException) DismissKeyguardTask(com.android.tools.idea.run.tasks.DismissKeyguardTask) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ApkProvisionException

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

the class BlazeAndroidBinaryMobileInstallRunContext 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 9 with ApkProvisionException

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

the class BlazeNativeAndroidDebugger method attachToClient.

@Override
public void attachToClient(Project project, Client client) {
    final String clientDescr = client.getClientData().getClientDescription();
    Module module = null;
    final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
    for (AndroidFacet facet : facets) {
        try {
            final String packageName = ApkProviderUtil.computePackageName(facet);
            if (clientDescr.startsWith(packageName)) {
                module = facet.getModule();
                break;
            }
        } catch (ApkProvisionException ignored) {
        // ignored
        }
    }
    if (module == null) {
        throw new RuntimeException("Cannot find module by package name");
    }
    if (hasExistingSession(project, client)) {
        return;
    }
    // Detach any existing JDWP debug session - reusing an existing session is troublesome
    // because we need to setup a custom XDebugProcess.
    DebuggerSession debuggerSession = findJdwpDebuggerSession(project, getClientDebugPort(client));
    if (debuggerSession != null) {
        debuggerSession.getProcess().stop(false);
    }
    // Create run configuration
    // TODO: Important modification here. Make sure to keep this in refactor.
    // We need a custom BlazeAndroidNativeAttachConfiguration to skip a bunch of launch checks so
    // validate passes.
    ConfigurationFactory factory = BlazeAndroidNativeAttachConfigurationFactory.getInstance();
    String runConfigurationName = String.format("Android Native Debugger (%d)", client.getClientData().getPid());
    RunnerAndConfigurationSettings runSettings = RunManager.getInstance(project).createRunConfiguration(runConfigurationName, factory);
    AndroidNativeAttachConfiguration configuration = (AndroidNativeAttachConfiguration) runSettings.getConfiguration();
    configuration.setClient(client);
    configuration.getAndroidDebuggerContext().setDebuggerType(getId());
    configuration.getConfigurationModule().setModule(module);
    // TODO: Important modification here. Make sure to keep this in refactor.
    // We need to set the correct working dir to find sources while debugging.
    // See BlazeAndroidRunConfigurationDebuggerManager#getAndroidDebuggerState
    AndroidDebuggerState state = configuration.getAndroidDebuggerContext().getAndroidDebuggerState();
    if (state instanceof NativeAndroidDebuggerState) {
        NativeAndroidDebuggerState nativeState = (NativeAndroidDebuggerState) state;
        nativeState.setWorkingDir(WorkspaceRoot.fromProject(project).directory().getPath());
    }
    ProgramRunnerUtil.executeConfiguration(project, runSettings, DefaultDebugExecutor.getDebugExecutorInstance());
}
Also used : DebuggerSession(com.intellij.debugger.impl.DebuggerSession) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) AndroidDebuggerState(com.android.tools.idea.run.editor.AndroidDebuggerState) NativeAndroidDebuggerState(com.android.tools.ndk.run.editor.NativeAndroidDebuggerState) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) BlazeAndroidNativeAttachConfigurationFactory(com.google.idea.blaze.android.run.attach.BlazeAndroidNativeAttachConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AndroidNativeAttachConfiguration(com.android.tools.ndk.run.attach.AndroidNativeAttachConfiguration) Module(com.intellij.openapi.module.Module) NativeAndroidDebuggerState(com.android.tools.ndk.run.editor.NativeAndroidDebuggerState) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

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