I am developing a future open source Android library with Kotlin, and I'd like to count the methods from my own code as well as from dependencies.
Since how Kotlin differs from Java, I assume the tool should take an aar input as a file to get the real methods count, but I only found tools taking apk files as inputs so far.
How can I do it the simplest way?
Thanks for your help!
The dexcount-gradle-plugin works with libraries as well. The resulting #aar file should not differ when using Kotlin instead of Java, since Kotlin just compiles to Java byte code as well. So just use it and you'll get all the information you need for your library.
buildscript {
dependencies {
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4'
}
}
apply plugin: 'com.getkeepsafe.dexcount'
Related
I need to modify some class in Flutter framework during compilation of my Flutter application.
Thought, it's a good idea to use the byte-buddy-gradle-plugin for this purpose.
Added this into my app/build.gradle:
apply plugin: "net.bytebuddy.byte-buddy-gradle-plugin"
byteBuddy {
transformation {
plugin = "com.example.BuildPlugin"
// classPath = ...
}
}
BuildPlugin is executed succesfully on compileDebugKotlin task, but it processes only my project classes.
Is there any possibility to point it to flutter.jar somehow, maybe using classPath transformation parameter?
I tried to use this part from plugin README:
configurations {
examplePlugin "foo:bar:1.0"
}
with some modifications, but got "Gradle DSL method not found: 'examplePlugin()'" error.
Unfortunately, this is not really compatible to how build pipelines work. What you can do is that you use the shade plugin to copy a dependency's code into your project and then process it from there. Otherwise, Java agents would be the solution for this but Android does not support it.
I solved it by using Android Transform API and Javassist.
Please check my GitHub if anyone is interested how.
I have an android library that I distribute as a jar file; Currently it has zero dependencies (other than the things built into Java itself). I like the idea of porting it to kotlin, however I haven't been able to figure out how to do this without forcing a dependency on kotlin-stdlib (or kotlin-stdlib-jre7, etc)
I'm somewhat wary about doing this, because kotlin-stdlib gets updates very frequently (multiple times per month sometimes) and I don't want to cause a future compatibility problem.
Obviously if I use any of the kotlin specific functions or types (e.g. listOf, mapOf, etc) then of course I'd need the stdlib, but if I stick to pure java types and functions, then is this possible? And if so, how?
I am not sure this is what you are looking for but I was able to build and run run this simple program using IntelliJ Idea 2018.3
fun main() {
System.out.println("hello world")
}
and the following build.gradle file
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
}
apply plugin: 'application'
mainClassName = "MainKt"
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
The only thing I saw in the jar file, other than a META-INF folder was my MainKt.class
I was able to run this on the jvm using
java -classpath simple.jar MainKt
I think if you don't include the standard library you cant even use Kotlin's println function, so you have to resort to java's System.out.println method
I have seen and used compile, compile files, androidTestCompile etc for importing dependencies in my android project. Today I came across embedded in the gradle of an existing android project. Not sure what this means. Even googling didn't help me on this. Can anyone please help. Below is the line I saw in the build.gradle file.
embedded 'com.eyeverify:EVServiceInterface:2.6.1-release#aar'
The keyword embedded doesn't exist in Gradle syntax. I think in that android project, embedded was a custom configuration defined in a build.gradle file:
configurations {
embedded
}
So you can use:
embedded 'com.eyeverify:EVServiceInterface:2.6.1-release#aar'
I've been migrating to Gradle and I've encountered an awkward issue.
Using Intellij IDEA I found two ways to add a dependency, please see the pictures attached:
As I can see these two way are not interchangeable. But the way B is obviously equivalent to
dependencies {
compile project(':xx-manager-shared')
}
Could anyone explain to me that's the exact difference between these two methods of adding dependencies?
And how should I organise "cross dependencies" in Gradle when
A module depends on B module,
B depends on C
and C depends on A?
It seems in A the dependencies are for the Android module, and in B it is the dependencies required by the Gradle plugin for building, e.g. Annotation processing?
I would recommend you download and try out Android Studio, it looks a lot simpler since it is purpose built for Android development, and you get a simple list of modules, without the tree hierarchy above.
I generally add dependencies by hand, as it doesn't mess up the build.gradle files.
In answering your other question, you are defining circular dependencies, so if you can find a way around it it's best, otherwise you can try adding them, syncing with Gradle and seeing if it works.
Basically, I'm using an open-source library in my main project. The library is included by compile project('<path-to-lib>'). The trouble is, there're a lot of files/classes/resources which I don't really need. I only need a small subset of those. Instead of deleting redundant parts, is there any way for me to write Groovy/Gradle script to pick only essential parts for building? This way, ideally, I can make minimal changes to the library.
In the build file for the library you can tailor the source sets to your needs. In general you write something like this:
apply plugin: 'java'
sourceSets {
main {
java {
exclude 'some/unwanted/package/**'
}
}
}
I'm assuming this is a plain Java library. If it's an Android library, the android-library plugin also supports exclude syntax in source sets.
Here's a SO question for reference:
Android Studio Exclude Class from build?
You can also read the Gradle docs for source sets at http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.SourceSet.html#org.gradle.api.tasks.SourceSet:java(groovy.lang.Closure) and the Java plugin at http://www.gradle.org/docs/current/userguide/java_plugin.html