Intellij Idea import gradle project error - “Cause

2019-01-26 06:54发布

问题:

While importing project as gradle have error Cause: unexpected end of block data. Project has several modules. I'm using Idea 132.719 and 1.8 gradle.

回答1:

I see in your comments, @SergeyB, that deleting .gradle in your user dir didn't help, but these steps resolved my issue (which had similar symptoms):

  • Delete .gradle directory from user dir (\Users\Mark.gradle)
  • Delete GRADLE_HOME environment variable, if it's set
  • Delete "manual" installs of Gradle (which shouldn't be needed, since Gradle will automatically download the necessary files when you run the gradlew wrapper)
  • Run "gradlew" from command-line, and confirm that new files are downloaded
  • Run a gradle build from the command-line (e.g., "gradlew clean assemble")
  • If you get an SDK version mismatch error, such as "failed to find target android-18", be sure to download the corresponding Android SDK (which can be done via the SDK Manager in Android Studio)
  • Once you can build from the command-line, try again from within the IDE


回答2:

I had the same problem. Turned out the build.gradle specified a buildToolsVersion that was not installed:

android {
    buildToolsVersion "18.1"
    ...
}

while I only had 18.1.1 installed. Changing the buildToolsVersion in build.gradle fixed the problem for me. If this doesn't fix it for you, carefully inspecting the Intellij log might reveal the problem.

You can use the Android SDK Manager to see which version of the build tools is installed.



回答3:

Just open app/src/main/build.gradle and Android Studio will probably make a yellow highlight over the text version of buildToolsVersion

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"  //<--- THIS PART WILL BE HIGHLIGHTED

    defaultConfig {
    ...

This means that Gradle has tried to compile with the wrong version of Gradle build tool installed. Usually the version will be lower.

Open then Tools->Android->SDK Manager and find the highest version of Android SDK Build-Tools and wrote that version. In my case, it's 19.1.

Recompile and it will work.



回答4:

I had the same problem just after installation Android Studio version 0.6.1. The buildToolsVersion in \app\build.gradle pointed to correct version (19.0.3) however problem was fixed by changing it to version 19.1

android {
compileSdkVersion 19
buildToolsVersion "19.1" // <- This was changed from 19.0.3
...


回答5:

A good tip in with these type of problems if to use the command line version of gradlew, it can give you much more useful information, for the above problem it might look like this:

Error code from Android studio

Gradle 'bluetooth-new-circle' project refresh failed

Error:Cause: unexpected end of block data

Error code from command line gradlew with the same project:

~/source_code/bluetooth$ ./gradlew clean assembleDebug :AccessoryController:clean UP-TO-DATE :BluetoothAudioProxy:clean UP-TO-DATE :BluetoothGatt:clean UP-TO-DATE :ScaleMonitor:clean UP-TO-DATE :UsbMonitor:clean UP-TO-DATE :AccessoryController:preBuild FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':AccessoryController:preBuild'.

    The SDK Build Tools revision (19.0.2) is too low for project ':AccessoryController'. Minimum required is 19.1.0

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10.078 secs ~/source_code/bluetooth$



回答6:

I also had the same problem. I resolved this issue by setting ANDROID_HOME environmental variable. export ANDROID_HOME=/android_sdk_root_dir

Hope this helps.



回答7:

Very late answer, and I'm sure you don't care anymore, but someone else might.

  1. File -> Invalidate caches / Restart
  2. Shutdown Android Studio
  3. Rename/remove .gradle folder in the user home directory
  4. Restart Android Studio let it download all the Gradle stuff it needs
  5. Gradle build success !
  6. Rebuild project.... success !

Hope this helps .



回答8:

Try applying the idea plugin in Gradle and running it. Then open the project in IntellijIDEA with the .ipr file that is generated.



回答9:

yeah,

STEP 1: open the module build.gradle and find buildToolsVersion.

STEP 2: modified the value to the warning value.