链接个别本地源文件到Android Studio项目 [英] Link individual native source file to Android Studio project

查看:300
本文介绍了链接个别本地源文件到Android Studio项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找一个单独的源文件链接到一个Android Studio项目。我使用的是全新的Andr​​oid 1.3+工作室与NDK的支持。

I'm looking to link an INDIVIDUAL source file to an Android Studio project. I'm using the new Android Studio 1.3+ with NDK support.

在我模块的build.gradle文件,我可以通过链接整个源文件夹:

In my module's build.gradle file, I'm able to link entire source FOLDERS via:

android{
   sourceSets {
      main.jni.srcDirs += 'C:/users/jforce/native'
   }
}

以上块将添加在本地文件夹中的所有原始的源文件。

The above blocks will add all native source files in the 'native' folder.

不过,我希望增加单个源文件。例如。 JUST位于C文件:/users/jforce/native/test.c,而不会在同一文件夹中添加任何邻国文件

However, I'm looking to add individual source files. eg. JUST a file located at C:/users/jforce/native/test.c, without adding any neighboring files in the same folder.

下面是我到目前为止已经试过:

Here's what I've tried so far:

main.jni.sourceFiles.getFiles() += "C:/users/jforce/native/test.c"

Android的工作室不喜欢这一个。左操作数为红色,并强调值无效分配到显示,当我鼠标。这是令人困惑我,因为在Android /摇篮文档中说,该方法返回一组与通用的参数文件。 sourceSets.main.jni.srcDirs也返回一组与通用的参数文件,我能够合法地使用+ =操作上确定,但不是在这里。

Android Studio does not like this one. The left operand is underlined with red and 'Invalid value to assign to' is displayed when I mouse over. This is confusing to me, because the Android/Gradle documentation says that this method returns a Set with generic param File. sourceSets.main.jni.srcDirs also returns a Set with generic param File, and I'm able to legally use the += operator on that Set, but not here.

https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileCollection.html#getFiles()

<一个href=\"http://google.github.io/android-gradle-dsl/1.4/com.android.build.gradle.api.AndroidSourceDirectorySet.html\" rel=\"nofollow\">http://google.github.io/android-gradle-dsl/1.4/com.android.build.gradle.api.AndroidSourceDirectorySet.html

好吧,那么我想这一点:

Okay, so then I tried this:

main.jni.sourceFiles.getFiles().add("C:/users/jforce/native/test.c")

这默默的失败。我的项目建立没有错误,但源文件不被添加到我的项目。

This failed silently. My project builds without error, but the source file isn't added to my project.

作为万福玛利亚,我又试图这样的:

As a Hail Mary, I then tried this:

main.jni.sourceFiles.join("C:/users/jforce/native/test.c")

要在最后一次尝试类似,失败默默为好。该文件没有添加。

Similar to the last attempt, this fails silently as well. The file isn't added.

有谁知道如何单独的本地源文件正确链接到一个Android工作室1.3+项目?任何帮助将大大AP preciated。谢谢!

Does anyone know how to properly link an INDIVIDUAL native source file to an Android Studio 1.3+ project? Any help will be greatly appreciated. Thanks!

推荐答案

我想通了这一点。

android{
   sourceSets {
      main.jni.srcDirs += 'C:/users/jforce/native/test.c'
   }
}

作品。在本地文件夹中没有其它文件被添加。非常反直觉的财产暴露来源档案,但我知道了现在的工作!

Works. No other files in the 'native' folder are added. Very counter-intuitive with the sourceFiles property exposed, but I've got it working now!

这篇关于链接个别本地源文件到Android Studio项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆