android pdf框架,编译mupdf

因为mupdf编译的体积不小,之前也发过编译的文章,现在更新一下.

建一个mupdf_c目录,名字自己取,在里面git下载mupdf源码,把目录修改为libmupdf

mupdf_c目录下建build.gradle文件,内容如下

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

group = 'com.artifex.mupdf'
version = '1.22.2'

buildscript {
	repositories {
        maven {
            url "https://maven.aliyun.com/repository/public"
        }
        maven {
            url "https://maven.aliyun.com/repository/google"
        }
		maven { url "https://jitpack.io" }
		google()
		mavenCentral()
		maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
		maven { url "https://kotlin.bintray.com/kotlinx/" }
	}
	dependencies {
		classpath 'com.android.tools.build:gradle:7.4.1'
	}
}

allprojects {
	repositories {
        maven {
            url "https://maven.aliyun.com/repository/public"
        }
        maven {
            url "https://maven.aliyun.com/repository/google"
        }
		maven { url "https://jitpack.io" }
		google()
		mavenCentral()
		maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
		maven { url "https://kotlin.bintray.com/kotlinx/" }
	}
}

publishing {
	publications {
        // 定义一个名为 mupdf 的发布,
		// 运行./gradlew publishMupdfPublicationToLocalRepoRepository发布到下面定义的mupdf_c
		// ./gradlew publishMupdfPublicationToMavenLocal发布到.m2下面
		// ./gradlew publishMupdfPublicationToRemoteRepoRepository则是发布到远程,要配置远程仓库
		//maven {
		//	name = "remoteRepo"
		//	url = "http://my.org/repo"
		//}
        mupdf(MavenPublication) {
            groupId = "com.artifex.mupdf"
            artifactId = "mupdf-fitz"
            version = '1.0-SNAPSHOT'
            // 必须有这个 否则不会上传AAR包
            afterEvaluate { artifact(tasks.getByName("bundleReleaseAar")) }
            // 上传source,这样使用方可以看到方法注释
            //artifact generateSourcesJar
        }
    }
    repositories {
        maven {
            // 基于版本名称选择不同的仓库地址
            def releasesRepoUrl = "file:///Users/archko/pdf/mupdf_c/"
            def snapshotsRepoUrl = "file:///Users/archko/pdf/mupdf_c/"
			name = 'localRepo'
            // url是必须要配置的
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
            // 仓库用户名密码
            //credentials {
            //    username = "root"
            //    password = "root"
            //}
        }
    }
}

android {
	compileSdkVersion 34
	buildToolsVersion '34.0.0'

	defaultConfig {
		minSdkVersion 16
		targetSdkVersion 29
		externalNativeBuild.ndkBuild.arguments '-j4'

		// Set ABI_FILTERS in your gradle.properties file
		//if (project.hasProperty('ABI_FILTERS')) {
		//	ndk.abiFilters = []
		//	ndk.abiFilters.addAll(ABI_FILTERS.split(',').collect{it as String})
		//}
		ndk{
			abiFilters  "arm64-v8a" //,"armeabi-v7a"
		}
	}

	sourceSets {
		main {
			manifest.srcFile 'AndroidManifest.xml'
			java.srcDirs 'libmupdf/platform/java/src'
		}
	}

	externalNativeBuild {
		ndkBuild.path 'libmupdf/platform/java/Android.mk'
	}
	android.ndkVersion '25.2.9519653'
}

其它文件如gradle.properties,gradle目录,gradlew从别的工程弄过来就可以了.

manifest文件也要一个,内容:

然后运行:./gradlew publishMupdfPublicationToMavenLocal 就可以发布了.发完在自己工程最外的build.gradle加入mavenLocal()仓库,就可以引用到了,加两处.

你可能感兴趣的:(android,pdf)