Android 혼동 - 다른 패키지 이름과의 충돌 해결

질문

최근 제3자가 우리 aar를 통합했을 때 해당 프로젝트에서 도입한 다른 패키지 이름과 충돌하는 난독화된 파일이 나타났습니다.

해결책

기본적으로 난독화된 이름은 일반적으로 a, b, c, d 및 이들의 조합입니다. 난독화 규칙을 수정하고 난독화된 파일 명명 규칙을 제어함으로써 다른 패키지와 동일한 이름으로 인한 문제를 근본적으로 피할 수 있습니다. 구체적인 단계는 난독화 규칙 파일 proguard-rules.pro 에서 다음 설정을 지정하는 것입니다 .

-obfuscationdictionary filename.txt
-classobfuscationdictionary filename.txt
-packageobfuscationdictionary filename.txt
  • -obfuscationdictionary filename .txt: 클래스 이름, 멤버 변수 이름, 메서드 이름을 난독화하는 사전을 지정합니다.
  • -classobfuscationdictionary filename .txt: 클래스 이름을 난독화하기 위한 사전을 지정합니다. 사전 형식은 -obfuscationdictionary와 동일합니다.
  • -packageobfuscationdictionary filename .txt: filename은 패키지 이름을 난독화하기 위한 사전을 지정합니다. 사전 형식은 -obfuscationdictionary와 동일합니다.

filename.txt 는 난독화 후 생성된 이름을 지정하는 데 사용되는 사전 파일로, 사전 파일에서 공백, 구두점, 반복되는 단어, '#'으로 시작하는 줄은 무시됩니다. 사전을 추가한다고 해서 혼동 효과가 크게 개선되지는 않는다는 점에 유의해야 합니다. 사전을 추가하는 데는 두 가지 기능이 있습니다: 하나는 다른 패키지와의 혼동 및 이름 중복을 방지하는 것이고, 다른 하나는 읽기 어렵게 만드는 것입니다. proguard-rules.pro 디렉토리 수준
.
여기에 이미지 설명을 삽입하세요.
다음은 사전의 예입니다. 각 키워드 앞에 xxdo, xxif 와 같은 특수 접두사를 추가하는 것이 좋습니다.

# 使用java中的关键字作字典:避免混淆后与其他包重名,而且混淆之后的代码更加不利于阅读
#
# This obfuscation dictionary contains reserved Java keywords. They can't
# be used in Java source files, but they can be used in compiled class files.
# Note that this hardly improves the obfuscation. Decent decompilers can
# automatically replace reserved keywords, and the effect can fairly simply be
# undone by obfuscating again with simpler names.
# Usage:
#     java -jar proguard.jar ..... -obfuscationdictionary filename.txt
#

do
if
for
int
new
try
byte
case
char
else
goto
long
this
void
break
catch
class
const
final
float
short
super
throw
while
double
import
native
public
return
static
switch
throws
boolean
default
extends
finally
package
private
abstract
continue
strictfp
volatile
interface
protected
transient
implements
instanceof
synchronized
참고

1. 안드로이드 난독화 최적화: 난독화 후 다른 패키지의 클래스 이름과 충돌하는 문제를 해결하는 방법
2. 안드로이드 문자열 및 사전 난독화의 오픈 소스 구현

おすすめ

転載: blog.csdn.net/fengyulinde/article/details/106115757
おすすめ