无法解析符号'tools'和'GradleException'

Gui*_*shh 22 android gradle android-ndk

我已经开始研究包括Android NDK在内的现有项目.我在build.gradle中有两个问题,我不可能构建应用程序.为了您的信息,我的同事(正在研究它)能够构建应用程序.

我已经从项目结构中导入了NDK,我可以看到正确的Android NDK路径.

以下是build.gradle的样子:

import org.apache.tools.ant.taskdefs.condition.Os

buildscript {
repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    // The Fabric Gradle plugin uses an open ended version to react
    // quickly to Android tooling updates
    classpath 'io.fabric.tools:gradle:1.21.5'
}
}
allprojects {
repositories {
    maven { url "https://jitpack.io" }
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'

repositories {
maven { url 'https://maven.fabric.io/public' }
}

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
dataBinding{
    enabled = true;
}

defaultConfig {
    applicationId "com.lucien.myapp"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0.0"

    ndk {
        moduleName "DSPLib-jni"
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

sourceSets.main.jni.srcDirs = [] // disable automatic ndk-build call, which ignore our Android.mk
sourceSets.main.jniLibs.srcDir 'src/main/libs'

// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
    workingDir file('src/main')
    commandLine getNdkBuildCmd()
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

task cleanNative(type: Exec) {
    workingDir file('src/main')
    commandLine getNdkBuildCmd(), 'clean'
}

clean.dependsOn cleanNative

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:support-v4:24.2.0'

compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
compile 'com.orhanobut:dialogplus:1.11@aar'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
    transitive = true;
}
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.google.code.gson:gson:2.7'

}

def getNdkDir() {
if (System.env.ANDROID_NDK_ROOT != null)
    return System.env.ANDROID_NDK_ROOT

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkdir = properties.getProperty('ndk.dir', null)
if (ndkdir == null)
    throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")

return ndkdir

}

def getNdkBuildCmd() {
def ndkbuild = getNdkDir() + "/ndk-build"
if (Os.isFamily(Os.FAMILY_WINDOWS))
    ndkbuild += ".cmd"

return ndkbuild

}
Run Code Online (Sandbox Code Playgroud)

我在第一行遇到问题,尝试导入"org.apache.tools.ant.taskdefs.condition.Os":无法解析符号'tools'

工具问题

和"抛出新的GradleException("......")同样的问题"

GradleException问题

我是否需要在build.gradle中更新某些内容?或者问题出在其他地方?

谢谢 !

wal*_*kmn 20

您可以使用来自Java的任何其他可用异常,例如:

throw new FileNotFoundException("Could not read version.properties!")
Run Code Online (Sandbox Code Playgroud)

  • 也适用于 Flutter 项目。安卓工作室3.5 (3认同)

小智 20

非常简单 从 build.gradle 中删除new


小智 6

throw new GradleException(“未找到 Flutter SDK。在 local.properties 文件中使用 flutter.sdk 定义位置。”)

删除新的

throw GradleException(“未找到 Flutter SDK。在 local.properties 文件中使用 flutter.sdk 定义位置。”)