Home Features Docs Blog Support GitHub

Script: Automatically verify missing proguard rules when proguardLevel > 'app'


#1

When using proguardLevel higher than ‘app’, we will need to add all Delegate to proguard rules. But it’s not that easy to find all those in your project especially when you come back to config for your proguard rules after you finish all your codes instead of doing that during your coding process. And it is possible to forget to add these rules later in the maintenance of the project. So I wrote this python script to verify the rules during gradle build.

Put the file in the same directory as your proguard.append.cfg as well as your src dir, or change the path in the script.

Then you could simply run ./proguardVerify.py and it will verify your proguard file and if you miss something, a file called ‘proguard.missing’ will be generated with all missing rules in it.

Or you may add a gradle task to let it verifies during the build:

task verifyProguard(type: Exec) {
    workingDir './'

    commandLine 'python', 'proguardVerify.py'
}
moeMainProGuard {
    dependsOn verifyProguard
}

The script will check every import in your java file, and looking for anything stars with ‘apple.’ and ends with ‘Delegate’.
Then it will check your proguard.append.cfg and find rules like:
-keep interface apple.xxx.xxxDelegate { *; }


Simple Multi-OS Engine iOS App Size 140 MB
Simple Multi-OS Engine iOS App Size 140 MB
(Gergely Kis - Migeran) #2

Dear NoisyFox,

this is a very nice script, thank you for sharing!

Best Regards,
Gergely


(Gergely Kis - Migeran) #3

I created a new Knowledge Base category for posts like this.

Thanks again.


(Mateusz Bartos) #4

@Noisyfox - thank you, it have solved my problem :slight_smile:


(Saeed) #5

Dear @Noisyfox,

Can you give us an example from gradle file !
I cant use this and it send me error about moeMainProGuard.
I use MOE 2.x

Regards,
Saeed.


#6

Hmmm I’ve never tried on MOE 2.x. BTW is 2.0 released? I thought it’s still in alpha channel.


(Saeed) #7

I mean the alpha version. :blush:


#8

Could you upload the gradle outputs with verbose mode and enable stack trace?


(Saeed) #9

Edit my prost.

Gradle output.txt (11.5 KB)

Regards.


#10

Well it seems that MOE 2.x gradle plugin removed task moeMainProGuard.

Simply replace this task with another task which will be guaranteed to be executed before the compiling.


(Saeed) #11
moe {
    task verifyProguard(type: Exec) {
        workingDir './'

        commandLine 'python', 'proguardVerify.py'
    }

    dependsOn verifyProguard
}

Error:(47, 0) Could not find method dependsOn() for arguments [task ‘:ios:verifyProguard’] on object of type org.moe.gradle.MoeExtension.


(Saeed) #12

Dear @Noisyfox,

I change my moe version to 1.3.10 and now i have a pslog.txt (16.9 KB)
this problem

What went wrong ?

Regards,
Saeed.


#13

Show me your build.gradle and your project file structure.
Also make sure the default python version is 2.7 not 3.x.


(Saeed) #14

Project Sample contain {
Module app
Module common
Module ios contain {
proguardVerify.py
}
}

ios gradle:

buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
// Multi-OS Engine plugin
classpath group: ‘org.multi-os-engine’, name: ‘moe-gradle’, version: ‘1.3.10’
}
}

// Apply plugins
apply plugin: ‘eclipse’
apply plugin: ‘moe’

// Set source and target to Java 8
sourceCompatibility = “1.8”
targetCompatibility = “1.8”

// Set maven repository
repositories {
jcenter()
}

// Exclude all files from Gradle’s test runner
test { exclude ‘**’ }

// Setup Multi-OS Engine
moe {
xcode {
project ‘xcode/Sample.xcodeproj’
mainTarget ‘Sample’
testTarget ‘Sample-Test’

    // Uncomment and change these settings if you are working with a Xcode workspace
    // workspace 'xcode/Sample.xcworkspace'
    // mainScheme 'Sample'
    // testScheme 'Sample-Test'
}

// proguardLevel ‘all’

// task verifyProguard(type: Exec) {
// workingDir ‘./’
//
// commandLine ‘python’, ‘proguardVerify.py’
// }
//
// moeMainProGuard {
// dependsOn verifyProguard
// }
}

dependencies {
// Compile with ‘jar’ files in the project’s ‘lib’ directory
compile fileTree(include: ‘*.jar’, dir: ‘lib’)
compile project(’:common’)
}

// Setup Eclipse
eclipse {
// Set Multi-OS Engine nature
project {
natures ‘org.multi-os-engine.project’
}
}

common gradle:

apply plugin: ‘java’

dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
compile ‘com.squareup.retrofit2:retrofit:2.3.0’
compile ‘com.squareup.retrofit2:converter-gson:2.3.0’
compile ‘com.squareup.okhttp3:okhttp:3.8.0’
}

sourceCompatibility = “1.7”
targetCompatibility = “1.7”


(Saeed) #15

Dear @Noisyfox,

Any idea about this ?


#16

Try running the python script manually and see if there is any error message.


(Saeed) #17

Dear @Noisyfox,

I’am so tankful about your description.
It’s worked.

Regards,
Saeed.