apply plugin: 'com.android.library'
apply plugin: "org.jetbrains.kotlin.android"

android {
	namespace "org.nativescript.plugin_nativeprocessor"

	defaultConfig {
		compileSdk 34
		minSdkVersion 21
		targetSdkVersion 34

		externalNativeBuild {
			cmake {
				cppFlags "-frtti -fexceptions"
				abiFilters 'armeabi-v7a', "arm64-v8a", 'x86', 'x86_64'
				arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static", "-DWITH_QRCODE=1"
			}
		}
	}

	buildTypes {
		release {
			minifyEnabled false
			proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
		}
	}
	ndkVersion "26.3.11579264"
	externalNativeBuild {
		cmake {
			path "src/main/cpp/CMakeLists.txt"
		}
	}

//	kotlin {
//		jvmToolchain(17)
//	}
	compileOptions {
		sourceCompatibility JavaVersion.VERSION_17
		targetCompatibility JavaVersion.VERSION_17
	}
}

// ext.artifact = [
// 		'groupId': 'com.akylas',
// 		'id'     : 'canvas',
// 		'version': '1.0.0',
// 		'siteUrl': 'https://github.com',
// 		'gitUrl' : 'https://github.com',
// 		'userOrg': 'farfromrefug',
// 		'repo'   : 'android'
// ]

// version = artifact.version
// group = artifact.groupId

// install {
// 	repositories.mavenInstaller {
// 		pom.project {
// 			packaging 'jar'
// 			groupId artifact.groupId
// 			artifactId artifact.id
// 			version artifact.version
// 			name artifact.id 
// 			url artifact.siteUrl
// 			inceptionYear '2018' // HARDCODED
// 			licenses {
// 				license { // HARDCODED
// 					name 'GPL-3.0'
// 					url 'https://www.gnu.org/licenses/gpl.txt'
// 					distribution 'repo'
// 				}
// 			}
// 			scm {
// 				connection artifact.gitUrl
// 				developerConnection artifact.gitUrl
// 				url artifact.siteUrl
// 			}
// 		}
// 	}
// }

task sourcesJar(type: Jar) {
	from android.sourceSets.main.java.srcDirs
	archiveClassifier = "sources"
}

task javadoc(type: Javadoc) {
	source = android.sourceSets.main.java.srcDirs
	classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
	archiveClassifier = "javadoc"
	from javadoc.destinationDir
	// options.encoding = ‘UTF-8’
}

artifacts {
	archives sourcesJar
//	archives javadocJar
}


dependencies {
    implementation "androidx.annotation:annotation:1.1.0"
	implementation project(':ui-camera')

	def cameraxVersion =  project.hasProperty("cameraxVersion") ? project.cameraxVersion : "1.4.0-beta01"
	implementation "androidx.camera:camera-core:${cameraxVersion}"
	implementation "androidx.camera:camera-camera2:${cameraxVersion}"
	implementation "androidx.camera:camera-lifecycle:${cameraxVersion}"
	implementation "androidx.camera:camera-video:${cameraxVersion}"

	implementation "androidx.camera:camera-view:${cameraxVersion}"
	implementation "androidx.camera:camera-extensions:${cameraxVersion}"

	def androidXExifInterfaceVersion =  project.hasProperty("androidXExifInterfaceVersion") ? project.androidXExifInterfaceVersion : "1.3.3"
	implementation "androidx.exifinterface:exifinterface:$androidXExifInterfaceVersion"

	def androidXDocumentFileVersion =  project.hasProperty("androidXDocumentFileVersion") ? project.androidXDocumentFileVersion : "1.0.1"
	implementation "androidx.documentfile:documentfile:$androidXDocumentFileVersion"

	def itextpdfVersion = { -> project.hasProperty("itextpdfVersion") ? itextpdfVersion : "7.2.3" }
	implementation "com.itextpdf.android:kernel-android:$itextpdfVersion"
	implementation "com.itextpdf.android:layout-android:$itextpdfVersion"
}
//repositories {
//	mavenCentral()
//	def pathToPlugin = "/home/mguillon/dev/nativescript/com.akylas.documentscanner/node_modules/@nativescript-community/ui-cameraview/platforms/android"
//	flatDir {
//		dirs(pathToPlugin)
//	}
//}


//repositories {
//	mavenCentral()
//	def pathToPlugin  ="$rootDir/../../node_modules/@nativescript-community/ui-cameraview/platforms/android"
//	flatDir {
//		dirs(pathToPlugin)
//	}
//}

tasks.configureEach { DefaultTask currentTask ->
	// added because of a error with gradle 8 telling us to add this
	// because buildMetadata uses the output of those
	// TODO: there must be a way to make it simpler
	if (currentTask =~ /bundleLibCompileToJarDebug/) {
		currentTask.finalizedBy(":app:cleanupAllJars")
//		cleanupAllJars.dependsOn(currentTask)
	}
}