CompilerManager#make does not all tasks in case of a Android module/project Follow
Hi,
I need to trigger the compilation. I do this like this:
CompilerManager cm = CompilerManager.getInstance(project);
CompileScope compileScope = cm.createModulesCompileScope(modules, true, true);
cm.make(compileScope, new CompileStatusNotification() { .. });
This works in basic java projects, also with maven projects.
But after some more testing I found out that this does not work
with a Android module/project (I use the Android Plugin with IDEA Build #IU-145.971, and not Android Studio):
In case of a Android module/project CompilerManager#make does a few jobs but not all.
At least it does NOT execute the Gradle task :assembleDebug.
assembleDebug generates the .class files and this is exactly what I need (up-to-date .class files).
I have already compared whats the difference between my call and the "normal" call over the UI,
especially I have looked at CompileContext passed to CompileDriver#compileInExternalProcess
and the scopes (TargetTypeBuildScope) which are finally passed to "buildManager.scheduleBuild".
Finally I have figure out that I need to set the (Android)RunConfiguration on my compileScope,
like this:
RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(project).getSelectedConfiguration();
if (runnerAndConfigurationSettings != null) {
RunConfiguration runConfiguration = runnerAndConfigurationSettings.getConfiguration();
if (runConfiguration != null) {
compileScope.putUserData(CompileStepBeforeRun.RUN_CONFIGURATION, runConfiguration);
compileScope.putUserData(CompileStepBeforeRun.RUN_CONFIGURATION_TYPE_ID, runConfiguration.getType().getId());
}
}
After that the Gradle task :assembleDebug will be also executed.
Note that I am not familiar with the Build process of Gradle in general and/or Android build stuff.
Explicitly set the (current) RunConfiguration feels a bit strange
and I want not to depend on such settings whenever possible
My question:
Is there a better way to trigger compilation without depending on RunConfiguration ?
Thanks
Please sign in to leave a comment.
Furthermore, I have noticed that CompilerManager#createFilesCompileScope(VirtualFile[])
does not work in case of a Android module ("assembleDebug" is not invoked),
even if (Android)RunConfiguration is set.
Compilation for Android modules/projects is provided by Google, so for us it's a blackbox as well as any third-party plugin.