Step-by-step documentation for Android project set-up


#1

Hi there,

I was wondering if there is a document explaining how to set up a project manually without the project generator. I am trying to integrate openFrameworks with a React Native application by running oF in a different activity as RN. I was able to achieve this on iOS by integrating oF with a RN project, but on Android everything seems to be a big mess with the gradle build scripts. (or maybe I don’t have enough knowledge about it)

Would really appreciate some help on this topic. Have you tried integrating oF on Android into an existing application before?

Cheers,
Raz


#2

I took another route and I created a fresh oF project where I try to integrate RN. The fresh oF project was working, but after I added the RN packages along with the non-experimental gradle, I reached a point where the build process throws a linker error when I try to run the app on a device or emulator.

It fails with the following error:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':linkOFAndroidAppX86DebugArm7SharedLibrary'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
	at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
	at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
	at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
	at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
	at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
	at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
	at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
	at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:50)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:43)
	at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:40)
	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
	at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
	at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:75)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
	at org.gradle.util.Swapper.swap(Swapper.java:38)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
	at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.internal.operations.MultipleBuildOperationFailures: A build operation failed.
    Linker failed while linking libOFAndroidApp.so.
See the complete log at: file:///C:/Users/razva/Documents/devStuff/of_v0.10.0_android_release/apps/myApps/dummyRN/android/build/tmp/linkOFAndroidAppX86DebugArm7SharedLibrary/output.txt
	at org.gradle.internal.operations.DefaultBuildOperationQueue.waitForCompletion(DefaultBuildOperationQueue.java:100)
	at org.gradle.internal.operations.DefaultBuildOperationProcessor.run(DefaultBuildOperationProcessor.java:60)
	at org.gradle.nativeplatform.toolchain.internal.gcc.GccLinker.execute(GccLinker.java:64)
	at org.gradle.nativeplatform.toolchain.internal.gcc.GccLinker.execute(GccLinker.java:37)
	at org.gradle.nativeplatform.internal.BuildOperationLoggingCompilerDecorator.execute(BuildOperationLoggingCompilerDecorator.java:38)
	at org.gradle.nativeplatform.internal.BuildOperationLoggingCompilerDecorator.execute(BuildOperationLoggingCompilerDecorator.java:22)
	at org.gradle.nativeplatform.tasks.AbstractLinkTask.link(AbstractLinkTask.java:198)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
	at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:632)
	at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:615)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
	... 81 more
Caused by: org.gradle.nativeplatform.toolchain.internal.CommandLineToolInvocationFailure: Linker failed while linking libOFAndroidApp.so.
	at org.gradle.nativeplatform.toolchain.internal.DefaultCommandLineToolInvocationWorker.execute(DefaultCommandLineToolInvocationWorker.java:85)
	at org.gradle.nativeplatform.toolchain.internal.DefaultCommandLineToolInvocationWorker.execute(DefaultCommandLineToolInvocationWorker.java:30)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$OperationHolder.runBuildOperation(DefaultBuildOperationQueue.java:169)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$OperationHolder.run(DefaultBuildOperationQueue.java:162)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	... 5 more

my new build.gradle looks like this:

def ofRoot(){ return '../../../../' }

// Load common functions
apply from: ofRoot()+"libs/openFrameworksCompiled/project/android/common-functions.gradle"

buildscript {
    apply from: "../../../../libs/openFrameworksCompiled/project/android/ndk-verify.gradle"

    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        // Using the gradle-experimental version that supports c++
        classpath 'com.android.tools.build:gradle-experimental:0.9.3'
        classpath 'com.android.tools.build:gradle:2.3.3' // added a version that seemed compatible with the experimental one
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

apply plugin: 'com.android.model.application'

model {
    android {
        // openFrameworks currently only supports compiling against SDK 19
        compileSdkVersion = 25
        buildToolsVersion = "25.0.3"

        defaultConfig.with {
            minSdkVersion.apiLevel    = 19
            targetSdkVersion.apiLevel = 25
            versionCode     =  1
            versionName     = "1.0"
        }
    }

    android.ndk {
        moduleName = ofAppModuleName()
        toolchain  = buildToolchain()
        stl        = compilerStl()
        platformVersion = "19"
        abiFilters.addAll(["armeabi-v7a", "x86"]) // added this line to be able to run it on my device
    }

    android.sources {
        main {
            jni {
                source {
                    srcDirs= appSrcDirs(ofRoot())

                    includes = srcIncludes(ofRoot())
                    excludes = srcExcludes(ofRoot())
                }

                // Link to openFrameworks
                dependencies {
                    project ":openFrameworksProject"  linkage "static"
                }
            }

            manifest {
                source {
                    srcDirs = [ "." ]
                }
            }
            res {
                source {
                    srcDirs = [ "res" ]
                }
            }
            java {
                source {
                    srcDirs = [ "srcJava" ]
                }
            }
            aidl {
                source{
                    srcDirs = ['srcJava']
                }
            }
            renderscript{
                source{
                    srcDirs = ['srcJava']
                }
            }
            jniLibs {
                source {
                    srcDirs = ['libs']
                }
            }
            assets {
                source {
                    srcDirs = ['bin/data'] + addonData(ofRoot())
                }
            }
        }
    }

    android.lintOptions {
        abortOnError  = false
    }

    android.buildTypes {
        release {
            minifyEnabled = false
        }
    }

    // Setup the different types of flavors (arm / x86),
    // and add linker flags based on that
    android.productFlavors {
        getAbis().each { abi ->
            create(getFlavorName(abi)) {
                ndk {
                    abiFilters.add(abi)

                    cppFlags.addAll(coreCppFlags(abi, ofRoot()))
                    cppFlags.addAll(addonCppFlags(abi, ofRoot()))

                    ldLibs.addAll(coreLdLibs(abi, ofRoot()))
                    ldLibs.addAll(addonLdLibs(abi, ofRoot()))

                    ldFlags.addAll(coreLdFlags(abi, ofRoot()))
                    ldFlags.addAll(addonLdFlags(abi, ofRoot()))
                }
            }
        }
    }
}


dependencies {
    addonJavaDependencies(ofRoot()).each { dep ->
        compile(project(path: dep[1] ))
    }
    compile project(path: ':ofAndroidLib')
    // next, compile RN dependencies
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile "com.facebook.react:react-native:+"
}

Does anyone have an idea what’s going wrong here? Will really appreciate some help on this one