Skip to content

Instantly share code, notes, and snippets.

@shumoapp
Last active September 27, 2015 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shumoapp/91d815de6e01f5921d1f to your computer and use it in GitHub Desktop.
Save shumoapp/91d815de6e01f5921d1f to your computer and use it in GitHub Desktop.
Patch to be applied after importing an Eclipse NDK project into Android Studio.
Index: app/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/build.gradle (date 1443367227000)
+++ app/build.gradle (date 1443367317000)
@@ -1,23 +1,40 @@
-apply plugin: 'com.android.application'
+apply plugin: 'com.android.model.application'
+model {
-android {
+ android {
- compileSdkVersion 21
- buildToolsVersion "23.0.1"
+ compileSdkVersion = 23
+ buildToolsVersion = '23.0.1'
- defaultConfig {
- applicationId "com.example.nativeaudio"
- minSdkVersion 9
- targetSdkVersion 9
-
- ndk {
- moduleName "native-audio-jni"
+ defaultConfig.with {
+ applicationId = "com.example.nativeaudio"
+ minSdkVersion.apiLevel = 9
+ targetSdkVersion.apiLevel = 9
+ versionCode = 1
+ versionName = "1.0"
}
+ compileOptions.with {
+ sourceCompatibility = JavaVersion.VERSION_1_7
+ targetCompatibility = JavaVersion.VERSION_1_7
- }
+ }
+ }
+ android.ndk {
+ moduleName = "native-audio-jni"
+ cppFlags += ["-std=c++11"]
+ ldLibs += ['android', 'log', 'OpenSLES']
+ stl = "gnustl_static"
+ }
- buildTypes {
+ android.buildTypes {
release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ minifyEnabled = false
+ proguardFiles += file('proguard-android.txt')
}
+ debug {
+ debuggable = true
- }
+ }
+ }
+ android.productFlavors {
+ create('all')
+ }
+
}
Index: build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- build.gradle (date 1443367227000)
+++ build.gradle (date 1443367317000)
@@ -4,7 +4,7 @@
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.3.0'
+ classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}
Index: gradle/wrapper/gradle-wrapper.properties
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- gradle/wrapper/gradle-wrapper.properties (date 1443367227000)
+++ gradle/wrapper/gradle-wrapper.properties (date 1443367317000)
@@ -1,6 +1,6 @@
-#Wed Apr 10 15:27:10 PDT 2013
+#Sun Sep 27 18:12:40 EEST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
@shumoapp
Copy link
Author

Apparently, NDK projects in Android Studio require special Gradle plugin ('com.android.tools.build:gradle-experimental:0.2.0'), and this plugin is supported only in Gradle versions 2.5 and up. Also, the module's build.gradle has significant changes in the syntax, and the android plugin name changed from 'com.android.application' to 'com.android.model.application'.

Oh, and make sure to set the Android Studio project to use the default gradle wrapper:
File>Settings>Build, Execution, Deployment>Build Tools>Gradle>"Use default gradle wrapper".
This will make sure the gradle version specified in gradle-wrapper.properties is used.

This patch was meant to be applied right after importing into Android Studio the native-audio ndk sample project (that comes bundled with the android nkd).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment