gradle构建+proguard加密

使用proguard-gradle混淆 Java Library 使用progruard-gradle混淆 Java Library 阅读详情
构建:build.gradle

加密:library.gradle

libuild.gradle

中文编码---utf-8

apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
buildDir = "target"
version = '1.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8
//设置文件编码  
[compileJava, javadoc, compileTestJava]*.options*.encoding = 'UTF-8'
	
//执行task时的JVM args上增加参数-Dfile.encoding=UTF-8,否则中文命名的资源打包后,无法解压。
	
// 设置 WebApp 根目录	
webAppDirName = 'WebContent' 
//sourceSets.main.java.srcDir 'src'   // 设置 Java 源码所在目录

sourceSets {
	client{
		output.classesDir 'bin/client'
	}
	common{
		output.classesDir 'bin/common'
	}
	core{
		output.classesDir 'bin/core'
	}
	dev{
		output.classesDir 'bin/dev'
	}
	main{
		output.classesDir 'bin/server'
	}
	modeling{
		output.classesDir 'bin/modeling'
	}
	test{
		output.classesDir 'bin/test'
	}
}

 
// 设置 maven 库地址
repositories {  
    mavenCentral() // 中央库
}
dependencies {
//	compile files('lib/common/android/apk/AXMLPrinter2.jar')
//	compile files('lib/common/datetime/joda-time-2.3.jar')
//	compile files('lib/common/sql/gsp.jar')
//	compile files('lib/common/weixin/commons-codec-1.9.jar')
	//某个文件夹下面全部依赖
	compile fileTree(dir: 'lib/common/', include: '**/*.jar')
}


dependencies {
	//providedCompile (在war插件中定义)可以确保 servlet-api 能够在编译时被引用,却不随 web 工程发布(运行时由 Web 容器提供)
    providedCompile 'javax.servlet:servlet-api:2.5' // 编译期
    providedRuntime 'javax.servlet:jstl:1.2'    // 运行时
    //testCompile group: 'junit', name: 'junit', version: '4.+'
    testCompile ( 
    	'junit:junit:4.11'
    )
    //compile 中的依赖必然也会被包括在 testCompile 和 runtime
    compile (
    		'io.netty:netty-all:5.0.0.Alpha1',
    		'com.caucho:hessian:4.0.38',
    		'redis.clients:jedis:2.4.1',
    		'cglib:cglib-nodep:3.1',
    		'org.springframework:spring-core:4.1.5.RELEASE',
    		'org.springframework:spring-beans:4.1.5.RELEASE',
    		'org.springframework:spring-context:4.1.5.RELEASE',
    		'com.eaio.uuid:uuid:3.2',
    		'org.apache.poi:poi:3.7',
    		'org.controlsfx:controlsfx:8.20.8',
    		'org.apache.camel:camel-core:2.13.2',
    		'com.google.guava:guava:17.0',
    		'com.google.code.gson:gson:2.3.1',
    		'com.thoughtworks.xstream:xstream:1.4.8',
    		'org.codehaus.woodstox:woodstox-core-asl:4.4.1',
    		'org.apache.httpcomponents:httpclient:4.3.6',
    		'org.apache.httpcomponents:httpcore:4.3.3',
    		'commons-fileupload:commons-fileupload:1.3.1',
    		'com.alibaba:fastjson:1.2.4',
    		'de.jensd:fontawesomefx:8.2'    ,
    		'com.fasterxml.jackson.core:jackson-databind:2.5.1',
    		'com.fasterxml.jackson.core:jackson-core:2.5.1',
    		'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.1',
    		'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
    )
}
 
// 设置 Project Facets
import org.gradle.plugins.ide.eclipse.model.Facet
eclipse {
    wtp {
        facet {
            facet name: 'jst.web', type: Facet.FacetType.fixed
            facet name: 'wst.jsdt.web', type: Facet.FacetType.fixed
            facet name: 'jst.java', type: Facet.FacetType.fixed
            facet name: 'jst.web', version: '2.5'
            facet name: 'jst.java', version: '1.8'
            facet name: 'wst.jsdt.web', version: '1.0'
        }
    }
}


// 显示当前项目下所有用于 compile 的 jar.
task listJars(description: 'Display all compile jars.') << {
  configurations.compile.each { File file -> println file.name }
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    baseName = 'miboom'
    from sourceSets.main.allSource
    //from fileTree('src/main/aidl').include('**/I*.aidl')
}

artifacts {
    archives sourcesJar
}


/*****************************************
 * 打包
 *****************************************/
//jar {
//    manifest {
//        //attributes 'Main-Class': 'com.javachen.gradle.HelloWorld'
//    	attributes 'Author': 'zzf'
//    }
//}
task jar_dev(type: Jar){
	 baseName 'miboom_dev'
	 from("bin/dev")
}
//不dependsOn: classes,gradle编译出错,直接使用eclipse工程的编译输出bin
task jar_mc_client(type: Jar) {      
    baseName 'mc_client'  
    from("bin/client")
    from("bin/server"){
    	//除去服务端app、mobile的terminal包及server,模块监听器。
    	exclude '**/app/**','**/server/**','**/*ModuleListener*','com/miboom/core/framework/terminal/**'
    	exclude "config/**"
		exclude '*.list'
    }
} 
task jar_mc_common(type: Jar) {  
    baseName 'mc_common'  
    from("bin/common"){
    	exclude '**/*.jj','**/*.jar','**/*.bat','**/*.tpl'
    }
}
task jar_ms_common(type: Jar) {  
    baseName 'ms_common'  
    from("bin/common"){
    	exclude '**/*.jj','**/*.jar','**/*.bat','**/*.tpl'
    }
}
task jar_mc_core(type: Jar) {  
    baseName 'mc_core'  
    from("bin/core"){
    	exclude '**/readme.txt'
    	exclude '**/*.javajet'
    }
}
task jar_ms_core(type: Jar) {  
    baseName 'ms_core'  
    from("bin/core"){
    	exclude '**/readme.txt'
    	exclude '**/*.javajet'
    }
}
task jar_server(type: Jar) {  
    baseName 'ms_server'  
    from("bin/server")
}
task jar_mc_modeling(type: Jar) {      
    baseName 'mc_modeling'  
    from("bin/modeling")
} 
task jar_ms_modeling(type: Jar) {      
    baseName 'ms_modeling'  
    from("bin/modeling")
} 
task jar_all(dependsOn: ['jar_mc_client','jar_mc_common','jar_ms_common','jar_mc_core','jar_ms_core','jar_server','jar_mc_modeling','jar_ms_modeling']) {
	print "jar all..."
} 


war{  
    dependsOn jar_all  
    from("$projectDir/src/main/resources") {  
        include "*.properties"  
        into("WEB-INF/classes")  
    }  
    classpath=classpath - sourceSets.main.output  
    classpath fileTree(dir:libsDir, include:"${project.name}-${version}.jar")  
}  
task('jarPath')<<{  
    configurations.runtime.resolve().each {  
        print it.toString()+";"  
    }  
    println();  
}  

apply from: 'library.gradle'


library.gradle

+jfxrt.jar包

keywords.txt参考proguard

//
// This Gradle build file illustrates how to process a program
// library, such that it remains usable as a library.
// Usage:
//     gradle -b library.gradle proguard
//

// Tell Gradle where to find the ProGuard task.

buildscript {
    repositories {
        //flatDir dirs: '../../lib'
    	flatDir dirs: './release/proguard5.2/lib'
//    	fileTree(dir: './target/libs', include: '**/*.jar')
    }
    dependencies {
        classpath ':proguard'
    }
}

// Define a ProGuard task.

task proguard(type: proguard.gradle.ProGuardTask) {

    // You should probably import a more compact ProGuard-style configuration
    // file for all static settings, but we're specifying them all here, for
    // the sake of the example.
    //configuration 'configuration.pro'

    // Specify the input jars, output jars, and library jars.
    // In this case, the input jar is the program library that we want to process.
    injars  'target/libs/ms_server-1.0.jar'
    injars  'target/libs/ms_modeling-1.0.jar'
    injars  'target/libs/ms_core-1.0.jar'
    injars  'target/libs/ms_common-1.0.jar'
    injars  'target/libs/mc_modeling-1.0.jar'
    injars  'target/libs/mc_core-1.0.jar'
    injars  'target/libs/mc_common-1.0.jar'
    injars  'target/libs/mc_client-1.0.jar'
    
    outjars 'target/libs/obfuscate/'
    libraryjars  "${System.getProperty('java.home')}/lib/rt.jar"
    libraryjars  "${System.getProperty('java.home')}/lib/ext/jfxrt.jar"
    dontwarn
    // Save the obfuscation mapping to a file, so we can de-obfuscate any stack
    // traces later on. Keep a fixed source file attribute and all line number
    // tables to get line numbers in the stack traces.
    // You can comment this out if you're not interested in stack traces.
    obfuscationdictionary 'keywords.txt'
    classobfuscationdictionary 'keywords.txt'
    packageobfuscationdictionary 'keywords.txt'
    
    printmapping 'out.map'
//    keepparameternames
    renamesourcefileattribute 'SourceFile'
    keepattributes 'Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod'

    // Preserve all annotations.

    keepattributes '*Annotation*'

    // Preserve all public classes, and their public and protected fields and
    // methods.

    keep 'public class * { \
        public protected *; \
    }'

    // Preserve all .class method names.

    keepclassmembernames 'class * { \
        java.lang.Class class$(java.lang.String); \
        java.lang.Class class$(java.lang.String, boolean); \
    }'

    // Preserve all native method names and the names of their classes.

    keepclasseswithmembernames includedescriptorclasses:true, 'class * { \
        native <methods>; \
    }'

    // Preserve the special static methods that are required in all enumeration
    // classes.

    keepclassmembers allowshrinking:true, 'enum * { \
        public static **[] values(); \
        public static ** valueOf(java.lang.String); \
    }'

    // Explicitly preserve all serialization members. The Serializable interface
    // is only a marker interface, so it wouldn't save them.
    // You can comment this out if your library doesn't use serialization.
    // If your code contains serializable classes that have to be backward
    // compatible, please refer to the manual.

    keepclassmembers 'class * implements java.io.Serializable { \
        static final long serialVersionUID; \
        static final java.io.ObjectStreamField[] serialPersistentFields; \
        private void writeObject(java.io.ObjectOutputStream); \
        private void readObject(java.io.ObjectInputStream); \
        java.lang.Object writeReplace(); \
        java.lang.Object readResolve(); \
    }'

    // Your library may contain more items that need to be preserved; 
    // typically classes that are dynamically created using Class.forName:

    // keep 'public class mypackage.MyClass'
    // keep 'public interface mypackage.MyInterface'
    // keep 'public class * implements mypackage.MyInterface'
}


Android 出海aab的资源混淆(兼容gradle7.0+) AabResGuard适配Gradle7.0+ 阅读详情

相关推荐

React Native APK打包全流程与优化指南

APK(Android Package Kit)是Android应用的安装包格式,包含应用代码、资源和清单文件。在跨平台开发中,React Native通过桥接机制将JavaScript代码与原生模块整合,最终生成混合型APK。生产环境打包需经过代码签名、资源压缩等关键步骤,能显著提升性能并减小体积。针对React Native项目,开发者需要配置Gradle构建系统,管理签名密钥,并可能启用ProGuard代码混淆。典型的应用场景包括企业应用分发、第三方商店发布等。本文详细介绍从环境配置到自动化构建的全流

weixin_33744141的博客 359

实现spring boot与普通jar加密

实现spring boot与普通jar加密

移动开发领域 Gradle 构建过程中的代码混淆配置

在移动开发中,代码安全至关重要。代码混淆是一种保护代码不被轻易反编译和破解的重要手段。本文的目的就是详细介绍在使用 Gradle 进行移动应用构建时,如何正确地进行代码混淆配置,范围涵盖 Android 平台下的 Gradle 构建过程。本文首先会介绍代码混淆的核心概念以及相关术语,接着通过故事引入详细解释核心概念及其之间的关系,并给出原理和架构的示意图与流程图。然后会阐述代码混淆配置的核心算法原理和具体操作步骤,涉及数学模型和公式的讲解。再通过项目实战展示代码实际案例和详细解释。

移动开发前沿的博客 1014

SpringBoot 多Module Proguard混淆(Gradle

使用文档:https://www.guardsquare.com/manual/homeProGuard是一个压缩、优化和混淆Java字节码文件的免费的工具,它可以删除无用的类、字段、方法和属性。可以删除没用的注释,最大限度地优化字节码文件。它还可以使用简短的无意义的名称来重命名已经存在的类、字段、方法和属性。常常用于Android开发用于混淆最终的项目,增加项目被反编译的难度。压缩(Shrink):检测并删除未使用的类,字段,方法和属性。优化(Optimize):分析并优化方法的字节码。

平凡岁月里星辰 3442

【使用Proguard混淆Gradle项目】

使用Proguard混淆Gradle项目

歪比巴卜 3306

Conceal集成指南:如何在不同构建系统中正确配置和使用

Conceal是Facebook开发的一款专为Android设计的快速加密库,提供简单易用的API来执行高效的数据加密和认证操作。本指南将详细介绍如何在不同构建系统中正确配置和使用Conceal,帮助开发者快速集成这个强大的Android加密工具。 ## 📦 快速开始:三种构建方式 Conceal支持多种集成方式,你可以根据自己的项目需求选择最合适的方法: ### 1. 使用Maven C

gitblog_00601的博客 834

Paranoid与Gradle完美结合:自动化Android字符串加密流程

**Paranoid** 是一款专为Android应用打造的字符串加密工具,通过与Gradle构建系统深度整合,实现了字符串加密流程的全自动化。本文将详细介绍如何在Android项目中配置和使用Paranoid插件,轻松提升应用的安全性。 ## 🚀 为什么选择Paranoid? Android应用中的硬编码字符串容易被反编译工具提取,可能导致API密钥、URL等敏感信息泄露。Paranoid

gitblog_00287的博客 384

从入门到精通:Paranoid Android字符串混淆完全手册

Paranoid是一款专为Android应用打造的字符串混淆工具,能有效保护应用中的敏感字符串数据,防止被轻易反编译获取。本文将从基础安装到高级配置,全面讲解如何利用Paranoid实现Android应用的字符串安全防护。 ## 📋 什么是Paranoid? Paranoid作为一款专业的Android字符串混淆工具,通过对代码中的字符串进行加密处理,使逆向工程者难以直接获取原始字符串内容。

gitblog_00459的博客 721

如何只在Debug模式下集成Stetho-Realm:保护生产环境安全

在Android开发中,数据库调试工具是开发者提升效率的重要助手。Stetho-Realm作为Realm数据库的调试模块,能够帮助开发者直观查看和管理Realm数据库内容。然而,直接将调试工具集成到生产环境中可能带来安全风险。本文将详细介绍如何在Debug模式下安全集成Stetho-Realm,确保开发便利性与生产环境安全性的完美平衡。 ## 为什么需要区分Debug与Release模式? 在

gitblog_00930的博客 330

Java源码保护实战:自定义类加载器与代码混淆构建反编译防御体系

在软件开发和交付过程中,代码保护是保障知识产权和核心业务逻辑安全的关键环节。其基本原理在于对编译后的字节码进行变换或加密,以增加逆向工程的难度。从技术价值看,有效的代码保护不仅能防止核心算法和业务逻辑被轻易窃取,还能在商业SDK交付、系统集成等场景中建立技术壁垒。具体到Java生态,字节码加密和混淆是两种主流且互补的技术路径。字节码加密侧重于静态存储安全,而代码混淆则致力于打乱逻辑结构,两者协同可构建纵深防御。本文聚焦于如何将自定义类加载器与ProGuard等混淆工具深度结合,通过构建加密、运行时动态解密

weixin_33935636的博客 354

Gradle 进行apk签名

关于apk签名,首先可以通过图形界面的方式是完全可以签名的,但是每次都这样是不是很麻烦,所以下面介绍通过Gradle进行apk签名 首先在build.gradle文件中配置如下信息 signingConfigs{ config{ storeFile file('/bisien.jks') //把加密文件放到你项目的根目录下 storePasswo...

weixin_39413778的博客 897

Compose Multiplatform 项目中使用混淆时遇到的 Bouncy Castle 签名问题解析

在 Compose Multiplatform 桌面应用开发中,当开发者启用代码混淆功能时,可能会遇到一个与 Bouncy Castle 加密库相关的安全异常。具体表现为应用运行时抛出 `java.lang.SecurityException: SHA-256 digest error for org/bouncycastle/operator/OperatorCreationException....

gitblog_00999的博客 480

proguard 的使用,加密jar包

下载6.2.2的 https://download.csdn.net/download/kouwoo/12548260 系统中默认放在C:\Users\Administrator\AppData\Local\Android\Sdk\tools\proguard是4.7的 把最新的6.2.2解压缩覆盖原来的就可以了 运行bin\proguardgui.bat 在input/Output中输入你要加密的jar文件和输出文件 , proguard的配置参考下面 https://blo...

babytiger的专栏 1323

SpringBoot应用代码保护实战:从ProGuard混淆到字节码加密

在Java应用开发中,代码保护是保障知识产权和提升应用安全性的重要环节。其核心原理在于通过技术手段增加反编译和逆向工程的难度,从而保护核心业务逻辑与敏感信息。对于广泛使用的SpringBoot框架应用,代码保护的技术价值尤为突出,它能有效防止核心算法、配置信息及业务规则在交付或部署后遭到泄露与恶意利用。在实际工程实践中,开发者常面临在便捷性、性能与安全性之间的权衡。常见的应用场景包括商业软件交付、部署于不受控环境、以及保护包含敏感处理逻辑的微服务等。本文聚焦于SpringBoot程序的代码保护,深入探讨了以

congsikuai0611的博客 353

Android资源加密实战:基于Gradle插件构建与运行时解密方案

在移动应用开发中,资源文件保护是应用安全的重要环节。通过对称加密算法对资源进行加密处理,可以有效防止APK反编译导致的资源泄露。Gradle作为Android官方构建工具,其插件机制允许开发者在编译期无缝集成加密流程,实现自动化资源保护。本文聚焦于AES加密算法在Gradle插件中的实践应用,详细解析如何通过自定义Task实现资源加密,并设计运行时解密机制。针对构建流程优化,探讨了Transform API与Task的权衡,以及如何避免deprecated gradle features带来的兼容性问题。该

weixin_34055787的博客 548

【Android 安全】DEX 加密 ( Proguard 简介 | Proguard 相关网址 | Proguard 混淆配置 )

一、Proguard 简介、 二、Proguard 相关网址、 三、Proguard 混淆配置

让 学习 成为一种 习惯 ( 韩曙亮 の 技术博客 ) 2217

idea java 代码混淆加密_Idea插件开发中使用ProGuard混淆代码

配置gradle插件gradle配置ProGuard插件buildscript {repositories {jcenter()}dependencies {classpath 'net.sf.proguard:proguard-gradle:6.2.2'}}添加混淆task// idea 依赖所在目录def ideaPath = "xxx"task proguard(type: proguard...

weixin_39671621的博客 2300

Android Studio:ProGuard 混淆配置

Android Studio 创建Module后,会自动生成 proguard-rules.pro 文件,在其中添加需要的规则即可对apk或jar进行混淆。

doris_d的专栏 1万+
上一篇: 【ExtJS】图片编辑器imagefield
下一篇: 【JavaFX】错误:找不到或无法加载主类
redvalley
博客等级 码龄23年 77粉丝 355原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值