Blog

Blog

PHODAL

IDEA Community Debug Android 插件

这是一个非常有趣的故事,所以我想写篇文章记录一下。

当然了,现在你已经可以直接在 IDEA Community 里直接 debug Android 插件了。

因为项目的需要,我需要分析 Android Studio 的架构,以支撑业务开发。这个时候,不可避免的,我就需要 Debug Android Studio。于是乎,我拿下了源码,开始要 debug 了。

Unable to build IDEA community on macOS with lost jdi

我遇到的第一个问题比较简单,就是如标题所说。于是,我给 Jetbrains 提了个 issue,紧接着,他们就帮解决了这个问题。这需要在:

File | Settings | Build, Execution, Deployment | CompilerUser-local build process VM options 里配置:-Dgroovyc.in.process=true -Dgroovyc.asm.resolving.only=false

对应的错误日志如下:

Groovyc: While compiling tests of intellij.groovy: java.lang.RuntimeException: java.lang.NoClassDefFoundError: com.sun.jdi.Value
    at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1118)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1098)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:640)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:618)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:595)
    at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:62)
    at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:119)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:81)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:167)
    at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.lambda$runGroovyc$0(InProcessGroovyc.java:77)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

而根据我的搜索来看,是缺少了 JDI。

紧接着,我遇到了第二个问题。

缺少 'org.jetbrains.kotlin' 插件

对应的错误日志如下:

2020-09-18 09:35:22,621 [    615]   WARN - llij.ide.plugins.PluginManager - Problems found loading plugins:
  The Android (id=org.jetbrains.android, path=~/android/intellij-community/out/production/intellij.android.plugin) plugin Plugin 'Android' requires plugin 'org.jetbrains.kotlin' to be installed 
2020-09-18 09:35:22,641 [    635]  ERROR - llij.ide.plugins.PluginManager - Missing essential plugins: org.jetbrains.android 
com.intellij.ide.plugins.PluginManagerCore$EssentialPluginMissingException: Missing essential plugins: org.jetbrains.android
    at com.intellij.ide.plugins.PluginManagerCore.checkEssentialPluginsAreAvailable(PluginManagerCore.java:1158)
    at com.intellij.ide.plugins.PluginManagerCore.initializePlugins(PluginManagerCore.java:1222)
    at com.intellij.ide.plugins.PluginManagerCore.loadAndInitializePlugins(PluginManagerCore.java:1468)
    at com.intellij.ide.plugins.PluginManagerCore.lambda$initPlugins$15(PluginManagerCore.java:850)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
    at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1705)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)

在我尝试了多种方式无效之后,又一次提了个 ticket: unable build Android Studio - Plugin 'Android' requires plugin 'org.jetbrains.kotlin' to be installed

可能我忘记提了在 IDEA 编译 Android Studio 的前提,他们让我尝试用 Android Studio 官网的方式来解决:Canary 9 中缺少 Kotlin 插件的解决方法

最后,他们回复到,在 IDEA 里编译 Android Studio 是不可能的,原先的配置也是有问题的。所以,他们加了一个 IDEA with Android 的配置来搞这事。

我们就可以用这个选项来 debug 了,对应的 configuration 如下:

<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="IDEA with Android" type="Application" factoryName="Application" singleton="true">
    <option name="ALTERNATIVE_JRE_PATH" value="BUNDLED" />
    <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
    <log_file alias="idea.log" path="$PROJECT_DIR$/system/idea/log/idea.log" />
    <log_file alias="build.log" path="$PROJECT_DIR$/system/idea/log/build-log/build.log" />
    <option name="MAIN_CLASS_NAME" value="com.intellij.idea.Main" />
    <module name="intellij.idea.community.main.android" />
    <shortenClasspath name="ARGS_FILE" />
    <option name="VM_PARAMETERS" value="-Xmx2g -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -XX:MaxJavaStackTraceDepth=10000 -XX:CICompilerCount=2 -ea -Dsun.io.useCanonCaches=false -Dapple.laf.useScreenMenuBar=true -Dsun.awt.disablegrab=true -Didea.jre.check=true -Didea.is.internal=true -Didea.debug.mode=true -Djdk.attach.allowAttachSelf -Dfus.internal.test.mode=true -Dkotlinx.coroutines.debug=off -Djdk.module.illegalAccess.silent=true -Didea.config.path=../config/idea -Didea.system.path=../system/idea -Didea.initially.ask.config=true -Didea.platform.prefix=Idea" />
    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/bin" />
    <RunnerSettings RunnerId="Debug">
      <option name="DEBUG_PORT" value="60786" />
      <option name="TRANSPORT" value="0" />
      <option name="LOCAL" value="true" />
    </RunnerSettings>
    <RunnerSettings RunnerId="Profile " />
    <RunnerSettings RunnerId="Run" />
    <ConfigurationWrapper RunnerId="Debug" />
    <ConfigurationWrapper RunnerId="Profile " />
    <ConfigurationWrapper RunnerId="Run" />
    <method v="2">
      <option name="Make" enabled="true" />
      <option name="Gradle.BeforeRunTask" enabled="true" tasks="setupAndroidPluginRuntimeForIdea" externalProjectPath="$PROJECT_DIR$/build/dependencies" vmOptions="" scriptParameters="" />
      <option name="BuildArtifacts" enabled="true">
        <artifact name="debugger-agent" />
      </option>
    </method>
  </configuration>
</component>

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Developer, Consultant, Writer, Designer

ThoughtWorks 高级咨询师

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 与我沟通

标签

最近的一些事

  • 最近我和我的同事们,一起在创建一个新的编程语言:Charj 。它是一个使用 Rust 编写的描述式、中间编程语言。GitHub: https://github.com/charj-lang/charj

    Nov. 14, 2020, 9:27 p.m. | China