Skip to content

Commit

Permalink
修复#397打包完成之后某些ui样式失效
Browse files Browse the repository at this point in the history
  • Loading branch information
wilinz committed Aug 19, 2022
1 parent 0ac87a5 commit b118b11
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 44 deletions.
13 changes: 12 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,15 @@

-keep class com.tencent.tbs.** {
*;
}
}

-keep class org.autojs.autoxjs.BuildConfig{
*;
}

-keep interface kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader{
*;
}
-keep class kotlin.reflect.jvm.internal.impl.serialization.deserialization.builtins.BuiltInsLoaderImpl{
*;
}
4 changes: 3 additions & 1 deletion app/src/main/java/org/autojs/autojs/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class App : MultiDexApplication() {

override fun onCreate() {
super.onCreate()
GlobalAppContext.set(this)
GlobalAppContext.set(
this, com.stardust.app.BuildConfig.generate(BuildConfig::class.java)
)
instance = WeakReference(this)
setUpStaticsTool()
setUpDebugEnvironment()
Expand Down
14 changes: 6 additions & 8 deletions app/src/main/java/org/autojs/autojs/build/DefaultSign.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ object DefaultSign {

@Throws(NoSuchAlgorithmException::class, IOException::class)
private fun zipAndSha1(dir: File, zos: ZipOutputStream, dos: DigestOutputStream, m: Manifest) {
val `arr$` = dir.listFiles()
val `len$` = `arr$`.size
for (`i$` in 0 until `len$`) {
val f = `arr$`[`i$`]
if (!f.name.startsWith("META-INF")) {
if (f.isFile) {
doFile(f.name, f, zos, dos, m)
val children = dir.listFiles()?:return
for (element in children) {
if (!element.name.matches(Regex("^META-INF/(MANIFEST.MF|CERT.RSA|CERT.SF)$"))) {
if (element.isFile) {
doFile(element.name, element, zos, dos, m)
} else {
doDir(f.name + "/", f, zos, dos, m)
doDir(element.name + "/", element, zos, dos, m)
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions autojs/src/main/assets/modules/__app__.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,10 @@ module.exports = function (runtime, global) {

app.versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
app.versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;

var buildConfig
if (context.getPackageName().startsWith("org.autojs.autoxjs")){
buildConfig = org.autojs.autoxjs.BuildConfig
}else{
buildConfig = org.autojs.autoxjs.inrt.BuildConfig
}

app.autojs = {
versionCode: buildConfig.VERSION_CODE,
versionName: buildConfig.VERSION_NAME
versionCode: com.stardust.app.GlobalAppContext.getBuildConfig().VERSION_CODE,
versionName: com.stardust.app.GlobalAppContext.getBuildConfig().VERSION_NAME
};

app.intentToShell = function(i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public View createViewForName(String name, HashMap<String, String> attrs) {
}
Class<?> clazz = Class.forName(name);
String style = attrs.get("style");
if (style == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
if (style == null) {
return (View) clazz.getConstructor(Context.class).newInstance(mContext);
} else {
int styleRes = Res.parseStyle(mContext, style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.graphics.Color;
import android.view.View;

import com.stardust.app.GlobalAppContext;

/**
* Created by Stardust on 2017/11/3.
*/
Expand All @@ -14,7 +16,7 @@ public class Colors {
public static int parse(Context context, String color) {
Resources resources = context.getResources();
if (color.startsWith("@color/")) {
return resources.getColor(resources.getIdentifier(color.substring("@color/".length()), "color", context.getPackageName()));
return resources.getColor(resources.getIdentifier(color.substring("@color/".length()), "color", GlobalAppContext.getAutojsPackageName()));
}
if (color.startsWith("@android:color/")) {
return Color.parseColor(color.substring(15));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.view.View;
import android.view.ViewGroup;

import com.stardust.app.GlobalAppContext;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -48,7 +50,7 @@ public static float parseToPixel(View view, String dimension) {
public static float parseToPixel(String dimension, Context context) {
if (dimension.startsWith("?")) {
int[] attr = {context.getResources().getIdentifier(dimension.substring(1), "attr",
context.getPackageName())};
GlobalAppContext.getAutojsPackageName())};
TypedArray ta = context.obtainStyledAttributes(attr);
float d = ta.getDimension(0, 0);
ta.recycle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import android.view.View;
import android.widget.ImageView;

import androidx.core.content.ContextCompat;

import com.stardust.app.GlobalAppContext;
import com.stardust.autojs.core.ui.inflater.ImageLoader;

import java.net.URL;
Expand Down Expand Up @@ -56,15 +59,15 @@ public Drawable parse(Context context, String value) {

public Drawable loadDrawableResources(Context context, String value) {
int resId = context.getResources().getIdentifier(value, "drawable",
context.getPackageName());
GlobalAppContext.getAutojsPackageName());
if (resId == 0)
throw new Resources.NotFoundException("drawable not found: " + value);
return context.getResources().getDrawable(resId);
return ContextCompat.getDrawable(context,resId);
}

public Drawable loadAttrResources(Context context, String value) {
int[] attr = {context.getResources().getIdentifier(value.substring(1), "attr",
context.getPackageName())};
GlobalAppContext.getAutojsPackageName())};
TypedArray ta = context.obtainStyledAttributes(attr);
Drawable drawable = ta.getDrawable(0 /* index */);
ta.recycle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Context;
import android.view.View;

import com.stardust.app.GlobalAppContext;

/**
* Created by Stardust on 2017/11/5.
*/
Expand All @@ -17,6 +19,6 @@ public static int parseStyle(Context context, String value) {
if (value.startsWith("@style/")) {
value = value.substring(7);
}
return context.getResources().getIdentifier(value, "style", context.getPackageName());
return context.getResources().getIdentifier(value, "style", GlobalAppContext.getAutojsPackageName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.res.Resources;
import android.view.View;

import com.stardust.app.GlobalAppContext;

/**
* Created by Stardust on 2017/11/4.
*/
Expand All @@ -15,7 +17,7 @@ public static String parse(Context context, String str) {
if (str.startsWith("@string/")) {
Resources resources = context.getResources();
return resources.getString(resources.getIdentifier(str, "string",
context.getPackageName()));
GlobalAppContext.getAutojsPackageName()));
}
return str;
}
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ dependencies {
api 'androidx.annotation:annotation:1.4.0'
api 'com.github.hyb1996:settingscompat:1.1.5'
implementation "androidx.activity:activity-ktx:1.5.1"
api "org.jetbrains.kotlin:kotlin-reflect:1.7.10"
}
7 changes: 7 additions & 0 deletions common/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep interface kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader{
*;
}
-keep class kotlin.reflect.jvm.internal.impl.serialization.deserialization.builtins.BuiltInsLoaderImpl{
*;
}
35 changes: 35 additions & 0 deletions common/src/main/java/com/stardust/app/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.stardust.app

import androidx.annotation.Keep
import kotlin.reflect.full.primaryConstructor

@Keep
data class BuildConfig(
@JvmField
val DEBUG: Boolean = false,
@JvmField
val APPLICATION_ID: String = "",
@JvmField
val BUILD_TYPE: String = "",
@JvmField
val FLAVOR: String = "",
@JvmField
val VERSION_CODE: Long = 0,
@JvmField
val VERSION_NAME: String = ""
) {
companion object {
fun generate(rawBuildConfigClass: Class<*>): BuildConfig {
if (rawBuildConfigClass.simpleName != "BuildConfig") {
throw Exception("please pass in build config and ignore code obfuscation!")
}
val constructor = BuildConfig::class.primaryConstructor!!
val paramList = mutableListOf<Any>()
for (field in constructor.parameters) {
val param = rawBuildConfigClass.getField(field.name!!).get(null)
param!!.let { paramList.add(it) }
}
return constructor.call(*paramList.toTypedArray())
}
}
}
31 changes: 19 additions & 12 deletions common/src/main/java/com/stardust/app/GlobalAppContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,34 @@ package com.stardust.app
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.stardust.app.GlobalAppContext
import android.os.Looper
import android.os.Build
import android.content.pm.PackageManager
import android.content.pm.PackageInfo
import android.graphics.drawable.Drawable
import android.os.Handler
import android.widget.Toast
import androidx.annotation.RequiresApi
import com.stardust.R
import java.lang.Exception
import android.os.Looper
import android.util.Log
import androidx.core.content.ContextCompat

/**
* Created by Stardust on 2018/3/22.
*/
object GlobalAppContext {

const val TAG = "GlobalAppContext"

@SuppressLint("StaticFieldLeak")
private var sApplicationContext: Context? = null
private var sHandler: Handler? = null
fun set(a: Application) {

@JvmStatic
lateinit var buildConfig: BuildConfig
private set

@JvmStatic
val autojsPackageName
get() = buildConfig.APPLICATION_ID

fun set(a: Application, buildConfig: BuildConfig) {
this.buildConfig = buildConfig
Log.d(TAG, buildConfig.toString())
sHandler = Handler(Looper.getMainLooper())
sApplicationContext = a.applicationContext
}
Expand All @@ -43,9 +51,8 @@ object GlobalAppContext {
return get().getString(resId, *formatArgs)
}

@RequiresApi(api = Build.VERSION_CODES.M)
fun getColor(id: Int): Int {
return get().getColor(id)
return ContextCompat.getColor(get(), id)
}

@JvmStatic
Expand Down
13 changes: 12 additions & 1 deletion inrt/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@

-keep class com.tencent.tbs.** {
*;
}
}

-keep class org.autojs.autoxjs.inrt.BuildConfig{
*;
}

-keep interface kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader{
*;
}
-keep class kotlin.reflect.jvm.internal.impl.serialization.deserialization.builtins.BuiltInsLoaderImpl{
*;
}
11 changes: 7 additions & 4 deletions inrt/src/main/java/com/stardust/auojs/inrt/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class App : Application() {
var TAG = "inrt.application";
override fun onCreate() {
super.onCreate()
GlobalAppContext.set(this)
GlobalAppContext.set(
this, com.stardust.app.BuildConfig.generate(BuildConfig::class.java)
)
Utils.init(this);
AutoJs.initInstance(this)
GlobalKeyObserver.init()
Expand Down Expand Up @@ -108,15 +110,16 @@ class App : Application() {
getString(R.string.key_keep_running_with_foreground_service),
false
)
if (keepRunningWithForegroundService){
val foregroundNotification = ForegroundNotification(GlobalAppContext.appName +"正在运行中",
if (keepRunningWithForegroundService) {
val foregroundNotification = ForegroundNotification(
GlobalAppContext.appName + "正在运行中",
"点击打开【" + GlobalAppContext.appName + "",
R.mipmap.ic_launcher
) //定义前台服务的通知点击事件
{ context, intent ->
Log.d(TAG, "foregroundNotificationClick: ");
val splashActivityintent = Intent(context, ScriptExecuteActivity::class.java)
splashActivityintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
splashActivityintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context!!.startActivity(splashActivityintent)
}
KeepLive.startWork(
Expand Down

0 comments on commit b118b11

Please sign in to comment.