-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
101 lines (95 loc) · 3.14 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha5'
}
}
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion '24.0.0 rc2'
defaultConfig {
applicationId 'net.twisterrob.jpegtest'
minSdkVersion.apiLevel 10
targetSdkVersion.apiLevel 19
versionCode 1
versionName '1.0'
}
ndk {
// com.android.build.gradle.managed.NdkBuildType
debuggable = true
// com.android.build.gradle.managed.NdkConfig
platformVersion = 10
toolchain = 'gcc'; // gcc | clang
toolchainVersion = ''
//noinspection UnnecessaryQualifiedReference for code completion
com.android.build.gradle.managed.NdkOptions var = it
var.moduleName = 'libjpeg_wrapper'
var.CFlags.add('-Wall'); var.cppFlags.add('-Wall')
var.CFlags.add('-Wextra'); var.cppFlags.add('-Wextra')
//var.ldLibs.add('android')
var.ldLibs.add('log') // android/log.h
var.ldLibs.add('jnigraphics') // android/bitmap.h
var.cppFlags.add('-std=c++11') // Add provisions to allow C++11 functionality
var.cppFlags.add('-fexceptions') // Enable exception handling
var.stl = 'gnustl_shared' // http://developer.android.com/ndk/guides/cpp-support.html
}
}
}
repositories {
jcenter()
ivy {
name 'libjpeg'
url 'http://www.ijg.org'
layout 'pattern', { artifact '/files/[module].[revision].[ext]' }
}
}
configurations {
download // separate configuration so no-one tries to use it
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
// http://www.ijg.org/files/jpegsrc.v9b.tar.gz see libjpeg ivy repository
download 'ijg-libjpeg:jpegsrc:v9b@tar.gz'
}
// Extract IJG LibJpeg from download dependency instead of checking in to version control
task extractLibJpeg(type: Copy) {
def zipPath = project.configurations.download.find { it.name.startsWith('jpegsrc') }
def outputDir = file("${projectDir}/src/main/jni/libjpeg")
from tarTree(zipPath)
into outputDir
// all paths must start with */ because the tar.gz file contains a folder
include '*/j*.c'
include '*/j*.h'
include '*/jconfig.txt'
rename 'jconfig.txt', 'jconfig.h'
// exclude everything else: they're not needed for compilation
include '*/README', '*/libjpeg.txt', '*/structure.txt', '*/filelist.txt'
doLast {
def extractedRoot = outputDir.listFiles()[0]
def tree
// copy basics
tree = project.fileTree(extractedRoot)
tree.exclude 'jpegtran*'
tree.exclude 'jmem*'
tree.copy { into outputDir }
// copy specifics
tree = fileTree(extractedRoot)
tree.include 'jmemmgr.*'
tree.include 'jmemsys.*'
tree.include 'jmemnobs.*'
tree.copy { into outputDir }
// clean up
extractedRoot.deleteDir()
}
}
tasks.clean.dependsOn tasks.cleanExtractLibJpeg
// For Android Studio Gradle Sync
tasks.whenTaskAdded { if (it.name == 'preBuild') it.dependsOn tasks.extractLibJpeg }
// For Compilation to be ready whenever needed
tasks.withType(org.gradle.language.c.tasks.CCompile).whenTaskAdded { it.dependsOn tasks.extractLibJpeg }
tasks.withType(org.gradle.language.cpp.tasks.CppCompile).whenTaskAdded { it.dependsOn tasks.extractLibJpeg }