Skip to content

Commit a8fdc23

Browse files
committed
Fixed issues related to Gradle 6 and Android Studio 4.0 gradle plugin
1 parent 017fb1b commit a8fdc23

File tree

12 files changed

+172
-133
lines changed

12 files changed

+172
-133
lines changed

third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dex/Mutf8.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static void encode(byte[] dst, int offset, String s) {
107107
* Returns an array containing the <i>modified UTF-8</i> form of {@code s}.
108108
*/
109109
public static byte[] encode(String s) throws UTFDataFormatException {
110-
int utfCount = (int) countBytes(s, true);
110+
int utfCount = (int) countBytes(s, false);
111111
byte[] result = new byte[utfCount];
112112
encode(result, 0, s);
113113
return result;

third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dex/StringData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public boolean equals(Object obj) {
5454
@Override
5555
public int byteCountInDex() {
5656
try {
57-
return Leb128.unsignedLeb128Size(value.length()) + (int) Mutf8.countBytes(value, true) + SizeOf.UBYTE;
57+
return Leb128.unsignedLeb128Size(value.length()) + (int) Mutf8.countBytes(value, false) + SizeOf.UBYTE;
5858
} catch (UTFDataFormatException e) {
5959
throw new DexException(e);
6060
}

tinker-build/tinker-patch-gradle-plugin/src/main/groovy/com/tencent/tinker/build/gradle/TinkerPatchPlugin.groovy

+4-5
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class TinkerPatchPlugin implements Plugin<Project> {
132132

133133
android.applicationVariants.all { variant ->
134134
def variantName = variant.name.capitalize()
135-
def variantData = variant.variantData
136135

137136
def instantRunTask = getInstantRunTask(variantName)
138137
if (instantRunTask != null) {
@@ -145,7 +144,7 @@ class TinkerPatchPlugin implements Plugin<Project> {
145144

146145
TinkerPatchSchemaTask tinkerPatchBuildTask = mProject.tasks.create("tinkerPatch${variantName}", TinkerPatchSchemaTask)
147146

148-
tinkerPatchBuildTask.signConfig = variantData.variantConfiguration.signingConfig
147+
tinkerPatchBuildTask.signConfig = variant.signingConfig
149148

150149
def agpProcessManifestTask = project.tasks.findByName("process${variantName}Manifest")
151150
String manifestOutputBaseDir
@@ -187,7 +186,7 @@ class TinkerPatchPlugin implements Plugin<Project> {
187186

188187
//resource id
189188
TinkerResourceIdTask applyResourceTask = mProject.tasks.create("tinkerProcess${variantName}ResourceId", TinkerResourceIdTask)
190-
applyResourceTask.applicationId = variantData.getApplicationId()
189+
applyResourceTask.applicationId = variant.mergedFlavor.applicationId
191190
applyResourceTask.variantName = variant.name
192191
applyResourceTask.resDir = resDir
193192

@@ -220,7 +219,7 @@ class TinkerPatchPlugin implements Plugin<Project> {
220219
}
221220

222221
// Add this multidex proguard settings file to the list
223-
boolean multiDexEnabled = variantData.variantConfiguration.isMultiDexEnabled()
222+
boolean multiDexEnabled = variant.mergedFlavor.multiDexEnabled
224223

225224
if (multiDexEnabled) {
226225
TinkerMultidexConfigTask multidexConfigTask = mProject.tasks.create("tinkerProcess${variantName}MultidexKeep", TinkerMultidexConfigTask)
@@ -518,4 +517,4 @@ class TinkerPatchPlugin implements Plugin<Project> {
518517
return multiDexKeepProguard
519518
}
520519

521-
}
520+
}

tinker-build/tinker-patch-gradle-plugin/src/main/groovy/com/tencent/tinker/build/gradle/transform/ImmutableDexTransform.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ public class ImmutableDexTransform extends Transform {
357357

358358
public static void inject(Project project, def variant) {
359359
project.logger.info("prepare inject dex transform ")
360-
if (!variant.variantData.variantConfiguration.isMultiDexEnabled()) {
361-
project.logger.warn("multidex is diable. we will not replace the dex transform.")
360+
if (!variant.mergedFlavor.multiDexEnabled) {
361+
project.logger.warn("multidex is disabled. we will not replace the dex transform.")
362362
return
363363
}
364364
if (!FileOperation.isLegalFile(project.tinkerPatch.oldApk)) {

tinker-sample-android/app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ android {
8686
* you can use multiDex and install it in your ApplicationLifeCycle implement
8787
*/
8888
multiDexEnabled true
89+
multiDexKeepProguard file("tinker_multidexkeep.pro")
8990
/**
9091
* buildConfig can change during patch!
9192
* we can use the newly value when patch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
#tinker multidex keep patterns:
3+
-keep public class * implements com.tencent.tinker.entry.ApplicationLifeCycle {
4+
<init>(...);
5+
void onBaseContextAttached(android.content.Context);
6+
}
7+
8+
-keep public class com.tencent.tinker.entry.ApplicationLifeCycle {
9+
*;
10+
}
11+
12+
-keep public class * extends com.tencent.tinker.loader.TinkerLoader {
13+
<init>(...);
14+
}
15+
16+
-keep public class * extends android.app.Application {
17+
<init>();
18+
void attachBaseContext(android.content.Context);
19+
}
20+
21+
-keep class com.tencent.tinker.loader.TinkerTestAndroidNClassLoader {
22+
<init>(...);
23+
}
24+
25+
#your dex.loader patterns here
26+
-keep class tinker.sample.android.app.SampleApplication {
27+
<init>(...);
28+
}
29+
30+
-keep class com.tencent.tinker.loader.** {
31+
<init>(...);
32+
}
33+
34+
-keep class android.support.test.internal** { *; }
35+
-keep class org.junit.** { *; }

tinker-sample-android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
}
88
dependencies {
99
if (project.hasProperty('GRADLE_3') && GRADLE_3.equalsIgnoreCase('TRUE')) {
10-
classpath 'com.android.tools.build:gradle:3.2.1'
10+
classpath 'com.android.tools.build:gradle:4.0.0-alpha09'
1111
} else {
1212
classpath 'com.android.tools.build:gradle:2.3.3'
1313
}

tinker-sample-android/gradle.properties

-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryErr
2020
TINKER_VERSION=1.9.14.3
2121
GRADLE_3=true
2222

23-
android.enableAapt2=false
2423
#tinker.aapt2.public=false
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Tue Oct 24 15:01:44 CST 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

tinker-sample-android/gradlew

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

33
##############################################################################
44
##
55
## Gradle start up script for UN*X
66
##
77
##############################################################################
88

9-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10-
DEFAULT_JVM_OPTS=""
9+
# Attempt to set APP_HOME
10+
# Resolve links: $0 may be a link
11+
PRG="$0"
12+
# Need this for relative symlinks.
13+
while [ -h "$PRG" ] ; do
14+
ls=`ls -ld "$PRG"`
15+
link=`expr "$ls" : '.*-> \(.*\)$'`
16+
if expr "$link" : '/.*' > /dev/null; then
17+
PRG="$link"
18+
else
19+
PRG=`dirname "$PRG"`"/$link"
20+
fi
21+
done
22+
SAVED="`pwd`"
23+
cd "`dirname \"$PRG\"`/" >/dev/null
24+
APP_HOME="`pwd -P`"
25+
cd "$SAVED" >/dev/null
1126

1227
APP_NAME="Gradle"
1328
APP_BASE_NAME=`basename "$0"`
1429

30+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31+
DEFAULT_JVM_OPTS=""
32+
1533
# Use the maximum available, or set MAX_FD != -1 to use that value.
1634
MAX_FD="maximum"
1735

18-
warn ( ) {
36+
warn () {
1937
echo "$*"
2038
}
2139

22-
die ( ) {
40+
die () {
2341
echo
2442
echo "$*"
2543
echo
@@ -30,6 +48,7 @@ die ( ) {
3048
cygwin=false
3149
msys=false
3250
darwin=false
51+
nonstop=false
3352
case "`uname`" in
3453
CYGWIN* )
3554
cygwin=true
@@ -40,26 +59,11 @@ case "`uname`" in
4059
MINGW* )
4160
msys=true
4261
;;
62+
NONSTOP* )
63+
nonstop=true
64+
;;
4365
esac
4466

45-
# Attempt to set APP_HOME
46-
# Resolve links: $0 may be a link
47-
PRG="$0"
48-
# Need this for relative symlinks.
49-
while [ -h "$PRG" ] ; do
50-
ls=`ls -ld "$PRG"`
51-
link=`expr "$ls" : '.*-> \(.*\)$'`
52-
if expr "$link" : '/.*' > /dev/null; then
53-
PRG="$link"
54-
else
55-
PRG=`dirname "$PRG"`"/$link"
56-
fi
57-
done
58-
SAVED="`pwd`"
59-
cd "`dirname \"$PRG\"`/" >/dev/null
60-
APP_HOME="`pwd -P`"
61-
cd "$SAVED" >/dev/null
62-
6367
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6468

6569
# Determine the Java command to use to start the JVM.
@@ -85,7 +89,7 @@ location of your Java installation."
8589
fi
8690

8791
# Increase the maximum file descriptors if we can.
88-
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
92+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
8993
MAX_FD_LIMIT=`ulimit -H -n`
9094
if [ $? -eq 0 ] ; then
9195
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -150,11 +154,19 @@ if $cygwin ; then
150154
esac
151155
fi
152156

153-
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154-
function splitJvmOpts() {
155-
JVM_OPTS=("$@")
157+
# Escape application args
158+
save () {
159+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160+
echo " "
156161
}
157-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
162+
APP_ARGS=$(save "$@")
163+
164+
# Collect all arguments for the java command, following the shell quoting and substitution rules
165+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166+
167+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169+
cd "$(dirname "$0")"
170+
fi
159171

160-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
172+
exec "$JAVACMD" "$@"

0 commit comments

Comments
 (0)