Skip to content

Commit a272b88

Browse files
committed
import liblsl for android only once
1 parent 27fb451 commit a272b88

File tree

7 files changed

+52
-203
lines changed

7 files changed

+52
-203
lines changed

AndroidStudio/CMakeLists.txt

Lines changed: 0 additions & 97 deletions
This file was deleted.
Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,34 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 24
5-
buildToolsVersion "23.0.2"
4+
compileSdkVersion 28
5+
buildToolsVersion "28.0.3"
66
defaultConfig {
77
applicationId "edu.ucsd.sccn.receivestringmarkers"
88
minSdkVersion 17
99
targetSdkVersion 24
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13-
externalNativeBuild {
14-
cmake {
15-
cppFlags "-std=c++11 -frtti -fexceptions"
16-
}
17-
}
1813
}
1914
buildTypes {
2015
release {
2116
minifyEnabled false
2217
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2318
}
2419
}
25-
externalNativeBuild {
26-
cmake {
27-
path "../CMakeLists.txt"
28-
}
29-
}
3020

3121
dexOptions {
3222
javaMaxHeapSize "2048m"
3323
}
34-
35-
sourceSets {
36-
main {
37-
java.srcDirs += '../../../liblsl-Java/src'
38-
}
39-
}
4024
}
4125

4226
dependencies {
43-
compile fileTree(dir: '../libs', include: ['*.jar'])
44-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27+
implementation fileTree(dir: '../libs', include: ['*.jar'])
28+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
4529
exclude group: 'com.android.support', module: 'support-annotations'
4630
})
47-
compile 'com.android.support:appcompat-v7:24.2.1'
48-
testCompile 'junit:junit:4.12'
49-
}
50-
51-
//copy native libraries to per project location
52-
task copyJniLibs(type: Copy) {
53-
from '../jniLibs'
54-
into 'src/main/jniLibs'
31+
implementation project(':liblsl-Java')
32+
implementation 'com.android.support:appcompat-v7:28.+'
33+
testImplementation 'junit:junit:4.12'
5534
}
56-
tasks.withType(JavaCompile) {
57-
compileTask -> compileTask.dependsOn(copyJniLibs)
58-
}
59-
clean.dependsOn 'cleanCopyJniLibs'
60-
Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,33 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 24
5-
buildToolsVersion "23.0.2"
4+
compileSdkVersion 28
5+
buildToolsVersion "28.0.3"
66
defaultConfig {
77
applicationId "edu.ucsd.sccn.sendstringmarkers"
88
minSdkVersion 17
9-
targetSdkVersion 24
9+
targetSdkVersion 26
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13-
externalNativeBuild {
14-
cmake {
15-
cppFlags "-std=c++11 -frtti -fexceptions"
16-
}
17-
}
1813
}
1914
buildTypes {
2015
release {
2116
minifyEnabled false
2217
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2318
}
2419
}
25-
externalNativeBuild {
26-
cmake {
27-
path "../CMakeLists.txt"
28-
}
29-
}
30-
31-
dexOptions {
20+
dexOptions {
3221
javaMaxHeapSize "2048m"
3322
}
34-
35-
sourceSets {
36-
main {
37-
java.srcDirs += '../../../liblsl-Java/src'
38-
}
39-
}
4023
}
4124

4225
dependencies {
43-
compile fileTree(dir: '../libs', include: ['*.jar'])
44-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26+
implementation fileTree(dir: '../libs', include: ['*.jar'])
27+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
4528
exclude group: 'com.android.support', module: 'support-annotations'
4629
})
47-
compile 'com.android.support:appcompat-v7:24.2.1'
48-
testCompile 'junit:junit:4.12'
49-
}
50-
51-
//copy native libraries to per project location
52-
task copyJniLibs(type: Copy) {
53-
from '../jniLibs'
54-
into 'src/main/jniLibs'
30+
implementation 'com.android.support:appcompat-v7:28.+'
31+
implementation project(':liblsl-Java')
32+
testImplementation 'junit:junit:4.12'
5533
}
56-
tasks.withType(JavaCompile) {
57-
compileTask -> compileTask.dependsOn(copyJniLibs)
58-
}
59-
clean.dependsOn 'cleanCopyJniLibs'
60-

AndroidStudio/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
buildscript {
44
repositories {
55
jcenter()
6+
google()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.3'
9+
classpath 'com.android.tools.build:gradle:3.2.0'
910

1011
// NOTE: Do not place your application dependencies here; they belong
1112
// in the individual module build.gradle files
@@ -15,6 +16,7 @@ buildscript {
1516
allprojects {
1617
repositories {
1718
jcenter()
19+
google()
1820
}
1921
}
2022

AndroidStudio/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

AndroidStudio/readme.txt

100644100755
Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
This is currently the most robust and straightforward way of making Android apps that incorporate LSL. These instructions apply to Android Studio 3.1.2. You will need to get jna-4.2.2.jar (from https://mvnrepository.com/artifact/net.java.dev.jna/jna/4.2.2) and put it in LSL/liblsl-Android/AndroidStudio/libs. You will need to get the native jna libraries from https://github.com/java-native-access/jna/tree/4.2.2/lib/native. Select branch 4.2.2 and download android-*.jar. Extract each of these jars, using 7-zip or similar, and create the following directory tree:
2-
LSL/liblsl-Android/AndroidStudio/jniLibs
3-
arm64-v8a
4-
libjnidispatch.so
5-
armeabi
6-
libjnidispatch.so
7-
armeabi-v7a
8-
libjnidispatch.so
9-
mips
10-
libjnidispatch.so
11-
mips64
12-
libjnidispatch.so
13-
x86
14-
libjnidispatch.so
15-
x86_64
16-
libjnidispatch.so
17-
18-
Yes the platform names are different in the jar files than in the required the directory structure, and yes the names are important. If you do this incorrectly, you get errors related to "missing libjnidispatch.so".
19-
20-
If you get errors related to native, built in functions such as fgetpos and fsetpos in cstdio, this implies a problem with the version of the ndk that you are using (revision 15c and 16b are broken for several platforms). Download Revision 14b from https://developer.android.com/ndk/downloads/older_releases.html to a volume with a lot of space (it is 2.36 GB). In Android Studio, go to File -> Project Structure -> SDK Location -> Android NDK location and set the path to point at android-ndk-r14b.
21-
22-
To run, select the desired module from the list box the the left of the green arrow, and click the green arrow.
23-
24-
The majority of the native build instructions are in CMakeLists.txt, with some in the project build.gradle files.
25-
26-
At this point, every module rebuilds its own version of liblsl.so. Hopefully Android Studio will one day support building a purely native library without redundancy.
27-
28-
If you would like to use LSL in an android app built in a different way, it is recommended that you build one project (such as ReceiveStringMarkers) and extract the needed compiled library files from the .apk file (using 7-zip or similar).
29-
30-
To make other Apps in Android Studio, the easiest way is to exit Android Studio, copy the SendStringMarkers folder and change every reference to SendStringMarkers in the copied folder to a new name (using a text editor).
31-
32-
To see more examples of Java with LSL, look in LSL/liblsl-Java. Those examples should copy of to Android with minimal effort.
33-
34-
1+
This is currently the most robust and straightforward way of making Android apps that incorporate LSL. These instructions apply to Android Studio 3.2.0.
2+
3+
jna 4.5.0 is automatically downloaded and included, so just in case something goes wrong you'll have to make sure your APK has `libjnidispatch.so` and `liblsl.so` in all CPU architecture dependent subdirectories of `lib`, e.g.
4+
5+
[your apk]/lib
6+
arm64-v8a
7+
libjnidispatch.so
8+
liblsl.so
9+
armeabi
10+
libjnidispatch.so
11+
liblsl.so
12+
...
13+
14+
To run, select the desired module from the list box the the left of the green arrow, and click the green arrow.
15+
16+
The majority of the native build instructions are in `../liblsl-Java/build.gradle` and `../liblsl/CMakeLists.txt`.
17+
18+
At this point, liblsl.so is built once for each target cpu architecture.
19+
20+
If you would like to use LSL in an android app built in a different way, it is recommended that you build one project (such as ReceiveStringMarkers) and extract the needed compiled library files from the .apk file (using 7-zip or similar).
21+
22+
To make other Apps in Android Studio, the easiest way is to exit Android Studio, copy the SendStringMarkers folder and change every reference to SendStringMarkers in the copied folder to a new name (using a text editor).
23+
24+
To see more examples of Java with LSL, look in LSL/liblsl-Java. Those examples should copy of to Android with minimal effort.
25+
26+

AndroidStudio/settings.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
include ':ReceiveStringMarkers', ':SendStringMarkers'
1+
include ':ReceiveStringMarkers'
2+
include ':SendStringMarkers'
3+
4+
// Tell gradle where to find liblsl-Java
5+
include 'liblsl-Java'
6+
project(':liblsl-Java').projectDir = new File('../../liblsl-Java')

0 commit comments

Comments
 (0)