Comments (16)
你是不是把插件那个位置放的比其他插件下面了
from component.
用的新的Variant Api的transformClassesWith接口,这个是在所有的transform前执行的
from component.
代码给我看下吧
from component.
插件注册代码:
private fun config(project: Project) {
HostnameLog.info("config plugin for project: ${project.name}")
val androidComponents =
project.extensions.getByType(AndroidComponentsExtension::class.java)
androidComponents.onVariants { variant ->
if (unselect(variant)) {
return@onVariants
}
variant.transformClassesWith(
HostnameScanInstrument::class.java,
InstrumentationScope.PROJECT
) { params ->
params.ipv4AddressRegion.set(extension.ipadressRegionMap)
params.hostnameRegion.set(extension.hostnameRegionMap)
params.hostnameFilter.set(extension.hostnameFilterRules)
params.hostnameReportDir.set(outputDir)
params.enable.set(extension.scanHostname.get())
params.ignoredClassPrefix.set(extension.ignoreClassPrefix.get())
}
variant.transformClassesWith(
HostnameInstrument::class.java,
InstrumentationScope.PROJECT
) { params ->
params.removeRule.set(extension.removeHostnameRule)
params.enable.set(extension.removeHostname.get())
params.ignoredClassPrefix.set(extension.ignoreClassPrefix.get())
}
}
}
from component.
实现代码
abstract class HostnameInstrument: AsmClassVisitorFactory {
override fun createClassVisitor(
classContext: ClassContext,
nextClassVisitor: ClassVisitor
): ClassVisitor {
val targets = config()[classContext.currentClassData.className]
return if (targets != null) {
HostnameLog.info("instrument on class ${classContext.currentClassData.className}")
return HostnameClassVisitor(
Opcodes.ASM7,
nextClassVisitor,
targets,
)
} else {
HostnameLog.info("ignore instrument on class ${classContext.currentClassData.className}" +
", reason: instrument target is not configured")
nextClassVisitor
}
}
override fun isInstrumentable(classData: ClassData): Boolean {
if (!parameters.get().enable.get()) {
return false
}
if (isSignedClass(classData.className)) {
HostnameLog.info("ignore class: ${classData.className}")
return false
}
return config().containsKey(classData.className)
}
private fun isSignedClass(className: String): Boolean {
for (prefix in parameters.get().ignoredClassPrefix.get()) {
if (className.startsWith(prefix)) {
return true
}
}
return false
}
private fun factory() = HostnameRemoveFactory.instance(parameters.get())
private fun config() = factory().config()
}
from component.
项目里面还有其它插件使用了transform,都是在transformClassesWithComponentPlugin之后执行的。在我没有使用上面的新插件之前是可以编译通过的,加上了我的插件就不行。上面的插件只是做一些扫描硬编码域名的操作,会通过ClassVisitor来读取class文件。即使不在ClassVisitor中修改类,经过ClassReader和ClassWriter后,得到的class数据还是会发生变化。受AsmClassVisitorFactory 接口的限制,不能直接返回原始的class数据
from component.
意思就是你自己写了一个插件是吧. 那你 gradle 中应用插件的顺序的代码 也给我看下
from component.
我还是建议把compoent插件中transform读取jar的方式改一下JarFile jarFile = new JarFile(jarInput.getFile(), false);
from component.
还有就是我改不是问题. 那我得弄懂先, 改了会不会出其他问题
from component.
插件顺序大致如下
apply plugin: 'com.google.firebase.firebase-perf' // firebase性能监测,有个AsmClassesTransform会对一些类进行插桩
apply plugin: 'com.xiaojinzi.component.plugin
apply plugin: 其它插件
Transform的执行顺序
AsmClassesTransform - firebase插件
transformClassesWithComponentPluginForOverseaRelease - component插件
然后会出现:
Caused by: java.lang.SecurityException: SHA1 digest error for org/bouncycastle/LICENSE.class
at com.xiaojinzi.component.plugin.util.IOUtil.readAndWrite(IOUtil.java:22)
at com.xiaojinzi.component.plugin.ModifyASMUtilTransform.transform(ModifyASMUtilTransform.java:146)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:284)
at com.android.build.gradle.internal.profile.NoOpAnalyticsService.recordBlock(NoOpAnalyticsService.kt:72)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:242)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
from component.
因为你构造JarFile默认把校验签名打开了,通过JarFile.getInputStream会检查签名的。下面是JarFile.getInputStream实现
/**
* Returns an input stream for reading the contents of the specified
* zip file entry.
* @param ze the zip file entry
* @return an input stream for reading the contents of the specified
* zip file entry
* @throws ZipException if a zip file format error has occurred
* @throws IOException if an I/O error has occurred
* @throws SecurityException if any of the jar file entries
* are incorrectly signed.
* @throws IllegalStateException
* may be thrown if the jar file has been closed
*/
public synchronized InputStream getInputStream(ZipEntry ze)
throws IOException
{
maybeInstantiateVerifier();
if (jv == null) {
return super.getInputStream(ze);
}
if (!jvInitialized) {
initializeVerifier();
jvInitialized = true;
// could be set to null after a call to
// initializeVerifier if we have nothing to
// verify
if (jv == null)
return super.getInputStream(ze);
}
// wrap a verifier stream around the real stream
return new JarVerifier.VerifierStream(
getManifestFromReference(),
ze instanceof JarFileEntry ?
(JarEntry) ze : getJarEntry(ze.getName()),
super.getInputStream(ze),
jv);
}
from component.
apply plugin: 'com.google.firebase.firebase-perf' // firebase性能监测,有个AsmClassesTransform会对一些类进行插桩
apply plugin: 'com.xiaojinzi.component.plugin
这两句调换顺序, 把我的放前面. 你看下还出现吗?
apply plugin: 'com.xiaojinzi.component.plugin
这句就是放在 com.android.application 这个插件后面就行了
from component.
这样是没有问题的,我本地构建时候firebase-perf插件是没有启用的,可以编译通过。但是我还是建议把读取JarFile的地方改一下
from component.
那就是 firebase-pref 插件的启用导致的呗.
我那个插件本就生成一个 ASMUtil 这个类而已. 没有其他作用, 本来就放最前面就可以了.
那你把 firebase-perf 插件放我的后面不就完了
from component.
是可以这样改,但要是后面的人遇到这个问题,那不得怀疑好几天人生是不是自己的插件写错了
from component.
不瞒你说
因为插件顺序导致的问题已经不是一个两个了.
我怎么全部解决, 你这个我还能改代码, 很多其他的连问题都找不到. 我咋解决
我也只能在文档中强调这个事情了, 其他我做不了啥
而且你看看这个 issue 的最开始回复就是叫你看看顺序的问题, 你也没关注
from component.
Related Issues (20)
- afterXXXAction的优先级 HOT 5
- 请问下plugin支持增量吗? HOT 2
- 关于跳转到第三方SDK HOT 6
- 依赖高概率的找不到 HOT 4
- Failed to resolve: com.github.xiaojinzi123.Component:component-impl:1.9.2-androidx-java8 HOT 3
- 咨询一下doOpenUri的问题 HOT 1
- 请问Component与ActivityResultContract如何配合使用? HOT 3
- 如何创建并获取一个带参的Service? HOT 1
- 如何判断一个url是否可以跳转? HOT 6
- forwardForResult再activity异常destroy后再次调用无效 HOT 2
- 关于Gradle编译优化的提示 HOT 15
- 单 Activity多Fragment 文档不够详情 HOT 1
- 模块和工程大了之后,编译速度特别慢, 是否支持模块化编译aar吗?比如 RocketX HOT 4
- module能否独立运行测试? HOT 2
- 使用com.xiaojinzi.component.plugin 编译报错 HOT 6
- 路由文档有些模块能生成有些不能生成
- 没有IApplicationLifecycle的模块中的ServiceImpl,无法通过ServiceManager.get 获取到
- 1.9.4版本app模块依赖1.9.3版本编译的aar时,路由、服务获取都是null HOT 2
- 关于Unable to instantiate appComponentFactory java.lang.ClassNotFoundException问题 HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from component.