OMG,终于解决了IntelliJ IDEA配合Android和gradle时出现UnsupportedOperationException的问题了!

很长一段时间以来,IntelliJ IDEA一直编译不了,烦死了,决定研究研究。

先编译一次,看看idea.log,什么都没有,界面上只有个UnsupportedOperationException,发现有个bulid-log文件夹,找到了有关的log:

2014-04-28 21:01:42,661 [   1947]   INFO - .incremental.IncProjectBuilder - java.lang.UnsupportedOperationException 
org.jetbrains.jps.incremental.ProjectBuildException: java.lang.UnsupportedOperationException
at com.android.tools.idea.jps.builder.AndroidGradleTargetBuilder.build(AndroidGradleTargetBuilder.java:104)
at com.android.tools.idea.jps.builder.AndroidGradleTargetBuilder.build(AndroidGradleTargetBuilder.java:76)
at org.jetbrains.jps.incremental.BuildOperations.buildTarget(BuildOperations.java:101)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:819)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:857)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:772)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:595)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:352)
at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:184)
at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:129)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:224)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:113)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:133)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:148)
at java.util.AbstractList.add(AbstractList.java:108)
at com.android.tools.idea.jps.builder.BuilderExecutionSettings.populateHttpProxyJvmOptions(BuilderExecutionSettings.java:133)
at com.android.tools.idea.jps.builder.BuilderExecutionSettings.(BuilderExecutionSettings.java:69)
at com.android.tools.idea.jps.builder.AndroidGradleTargetBuilder.build(AndroidGradleTargetBuilder.java:101)
... 18 more

这尼玛什么情况!?!?怎么会调用AbstractList.add?看了看jdk源码,里面只有一句抛出UnsupportedOperationException的语句。又去网上一查,一般是不可变的list在调用add的时候才会这样。。那到底是什么回事啊啊啊!?!?

于是我就去找com.android.tools.idea.jps.builder.AndroidGradleTargetBuilder的源码,找到了:

https://android.googlesource.com/platform/tools/adt/idea/+/jb-mr1.1-dev-plus-aosp%5E2/android-gradle-jps/src/com/android/tools/idea/jps/builder/AndroidGradleTargetBuilder.java


  1. /**
  2.    * Builds a Gradle-based Android project using Gradle.
  3.    */
  4.  @Override
  5.  publicvoid build(@NotNullAndroidGradleBuildTarget target,
  6.                    @NotNullDirtyFilesHolder<AndroidGradleBuildTarget.RootDescriptor,AndroidGradleBuildTarget> holder,
  7.                    @NotNullBuildOutputConsumer outputConsumer,
  8.                    @NotNullCompileContext context)throwsProjectBuildException,IOException{
  9.    JpsProject project= target.getProject();

  10.    BuilderExecutionSettings executionSettings;
  11.    try{
  12.       executionSettings=newBuilderExecutionSettings();
  13.    }catch(RuntimeException e){
  14.      thrownewProjectBuildException(e);
  15.    }

  16.     LOG.info("Using execution settings: " + executionSettings);


  17.    String[] buildTasks= getBuildTasks(project, context, executionSettings);
  18.    if(buildTasks.length==0){
  19.      String format="No build tasks found for project '%1$s'. Nothing done.";
  20.       LOG.info(String.format(format, project.getName()));
  21.      return;
  22.    }

  23.    String msg="Gradle build using tasks: "+Arrays.toString(buildTasks);
  24.     context.processMessage(newProgressMessage(msg));
  25.     LOG.info(msg);

  26.     ensureTempDirExists();

  27.    String androidHome=null;
  28.    if(!isAndroidHomeKnown(executionSettings)){
  29.       androidHome= getAndroidHomeFromModuleSdk(project);
  30.    }

  31.    String format="About to build project '%1$s' located at %2$s";
  32.     LOG.info(String.format(format, project.getName(), executionSettings.getProjectDir().getAbsolutePath()));

  33.     doBuild(context, buildTasks, executionSettings, androidHome);
  34.  }
这些代码也没有调用List.add啊?好吧,应该看下面的Caused By:

https://android.googlesource.com/platform/tools/adt/idea/+/jb-mr1.1-dev-plus-aosp%5E2/android-gradle-jps/src/com/android/tools/idea/jps/builder/BuilderExecutionSettings.java

可是居然没有com.android.tools.idea.jps.builder.BuilderExecutionSettings.populateHttpProxyJvmOptions这个函数!?

那看来是版本不同啊。。

等等,这个名字叫populateHttpProxyJvmOptions,岂不是把IntelliJ IDEA的代理设置变为jvm的参数!!!

突然想起我的InteliJ IDEA用了proxy了。。。

然后就去掉了proxy。。然后就可以了!!!


IntelliJ IDEA真是让人想不到!代理设置会影响编译。。。。。

好吧,终究是搞定了,大家有同样问题看看代理设置吧。


然后突然发现这个问题已经被解决了:https://code.google.com/p/android/issues/detail?id=67679

感觉我好2啊。

你可能感兴趣的:(java,android)