水之积也不厚,则其负大舟也无力
2018-04-25 15:13
采纳率: 100%
浏览 8.3k

安卓开发:org.gradle.tooling.BuildException:

在真机上出现这个异常
org.gradle.tooling.BuildException: Exception while generating InstantRun main resources APK

在真机上运行出现这个异常

我的清单文件
<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools"
package="com.example.lenovo.mynotebook">

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.example.lenovo.mynotebook.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>


<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
    tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.CAMERA" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:windowSoftInputMode="adjustUnspecified|stateHidden"
        >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".edit_activity"
        android:windowSoftInputMode="adjustUnspecified|stateHidden"
        >

    </activity>
</application>

 我的build.gradle(Project)
 // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


 我的build.gradle(app) 
```apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.lenovo.mynotebook"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:support-v4:27.1.1'
}



  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • ydw_ydw 2018-04-26 00:48
    已采纳

    因为依赖包的路径太长了。默认的情况下,gradle都在个人用户的目录下,有的人的名字长,有的名字短。名字长的一下子就溢出了,导致工程不能运行了。
    解决办法1
    把gradle的依赖包换一个地方。比如在eclipse中,通过gradle插件,直接修改目录即可。
    注意,新指定的目录不能为 .gradle或者类似 以.开头,否则会没有效果。

    依赖包太长的异常
    这个地方eclipse是乱码,所以定位问题就更加难了。

    CreateProcess error=206, ÎļþÃû»ò)չÃû
    Could not execute build using Gradle distribution ‘http://venus.vip.vip.com/tools/gradle/gradle-2.4-bin.zip‘.

    Caused by: java.io.IOException: Cannot run program “C:\Program Files\Java\jdk1.7.0_17\bin\java.exe” (in directory “D:\xxx\git_xxx\project\online\test-task-service”): CreateProcess error=206, ??????ò)???

    org.gradle.tooling.BuildException: Could not execute build using Gradle distribution ‘http://venus.vip.vip.com/tools/gradle/gradle-2.4-bin.zip‘.
    at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:57)

    点赞 1 打赏 评论

相关推荐 更多相似问题