I find it useful to simply automate adding include paths for my projects. 
Makes it far nicer to simply create directories and C++ on the fly without 
also needing to update the bowels of the main AS project's gradle build 
files (or, historically, make files). After all, we're programmers and our 
tools can the handle mundane stuff and while we go solve grander mysteries! 
:)

YMMV:
- I make assumption all paths from root down are worthy of "-I{path}".
  True for me. Though, maybe not for you/everyone.
  Can can add easily pass in a 'prune' list or filter to cull out unwanted 
directories.

- I use it on different projects. So I declared the method in an separate 
gradle file to 'apply from:'.
  It's simple enough to just inline too if desired.
  I had also thought to using caching someday, thus defined it as a method.
  However, the traversal hasn't slowed down my builds enough to warrant the 
extra attention.

- dirRoot could be expanded to accept and loop an array of roots to handle 
multi codetrees too.


/**
 * Accepts a root to search and list to hold results.
 * appends "-I{path" to the list for the source tree.
 *
 * Ideally, we'd cache this and periodically refresh so not regenerated 
each build (but ... later)
 * Alternatively, we could import an externally auto-generated list too I 
suppose. *shrug*
 * 
 * Example use:
 *   android.ndk {
 *      def listIncludePaths = []
 *      RecurseForHeaderPaths("my/jni/src/root", listIncludePaths)
 *
 *      // Iterate list and append to CFlags
 *      // NOTE:
 *      // - CFlags not passed to ccp ...
 *      // ... and cppFlags won't include CFlags ...
 *      // ... and cppFlags += CFlags is unwise/discouraged//defeats the 
purpose but _might_ suffice for simple projects.
 *      // So, anyway, just append to both separately
 *      listIncludePaths.each {
 *        String item = it
 *        CFlags += item
 *        cppFlags += item
 *      }
 *    }
 */
def RecursiveForHeaderPaths ( dirRoot, listIncludePathsResult )
{
    def dirSource = new File(dirRoot)
    dirSource.traverse(type: groovy.io.FileType.DIRECTORIES) {
        listIncludePaths << "-I" + it.path
    }

    // Log this for gradle build debugging purposes if --info flagged
    if (logger.isEnabled(LogLevel.INFO))
    {
        logger.info ("Auto declaring C++ include paths: ~~ Begin ~~")
        listIncludePaths.each {
            String item = it
            logger.info("  Path: " + item)
        }
        logger.info ("Auto declaring C++ include paths: ~~ Complete ~~")
    }
}





On Thursday, January 9, 2014 at 1:24:09 PM UTC-8, Johan Bilien wrote:
>
> Hi,
>
> I'm trying to port our JNI/NDK library to gradle at:
>
> https://github.com/jobi/android-leveldb/tree/gradle
>
>
> The NDK compilation fails, because some of our C++ files depend on headers 
> that are in subfolders of the jni/ folder:
>
>  What went wrong:
> Execution failed for task ':compileDebugNdk'.
> > com.android.ide.common.internal.LoggedErrorException: Failed to run 
> command:
>   /Users/jobi/android-ndk-r9c/ndk-build NDK_PROJECT_PATH=null 
> APP_BUILD_SCRIPT=/Users/jobi/src/android-leveldb/build/ndk/debug/Android.mk 
> APP_PLATFORM=android-19 
> NDK_OUT=/Users/jobi/src/android-leveldb/build/ndk/debug/obj 
> NDK_LIBS_OUT=/Users/jobi/src/android-leveldb/build/bundles/debug/jni 
> APP_ABI=all
>   Error Code:
>   2
>   Output:
>   In file included from 
> /Users/jobi/src/android-leveldb/src/main/jni/com_litl_leveldb_DB.cc:8:0:
>   /Users/jobi/src/android-leveldb/src/main/jni/leveldbjni.h:6:28: fatal 
> error: leveldb/status.h: No such file or directory
>   compilation terminated.
>   make: *** 
> [/Users/jobi/src/android-leveldb/build/ndk/debug/obj/local/armeabi-v7a/objs/leveldbjni//Users/jobi/src/android-leveldb/src/main/jni/com_litl_leveldb_DB.o]
>  
> Error 1
>
>
>
> Is there a way to add folders to the LOCAL_C_INCLUDES? By default it seems 
> only the jni/ folder is included.
>
>
> More generally, why is the gradle plugin generating its own Android.mk 
> Makefile, instead of using the one that comes with the project? It seems to 
> me this would be a lot more flexible.
>
> Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to