How to use Transform api in gradle? - android

I am new to Gradle, I'm now trying to use AOP to design a plugin that can manipulate bytecode. And I'm now trying to use transform API, however I cannot get the correct library imported, like TransformManager, etc.
I know this question is a little dumb but I don't really know what to do with it... So for the following, I just copied and pasted the code from the source I'm learning from, but It's the same when I'm writing the code myself, I can't import the correct library, instead, the auto-import is
import org.apache.tools.ant.taskdefs.Transform which I didn't find in the transform api.
Can anybody explain why? and how can I solve it?

Lack of dependence,add libraries into plugin_demo/build.gradle
dependencies {
implementation gradleApi()
implementation localGroovy()
//android gradle plugin libraries
implementation 'com.android.tools.build:gradle:3.3.0'
implementation 'com.android.tools.build:gradle-api:3.3.0'
}

Related

Android studio is not able to resolve import

I am trying to work on a sample project to learn MvRx. However, seems something is wrong. Android Studio is not able to find and import activityViewModel automatically.
1) I tried to import it manually by writing its package name but it is still gray.
2) From Gradle tab, I selected my root project and clicked on Refresh Gradle Project in order to refresh all dependencies. It did not help, too.
What is the problem?
If someone is getting same error even when using activityViewModel() in fragment, this answer may be helpful.
In my case I was using activityViewModel() inside fragment. Still I was getting this as well as many other errors. Finally I figured out that mvrx is now using kotlin coroutines and all dependencies on rxjava are removed in 2.0.0-beta1.
To solve this use
implementation "com.airbnb.android:mvrx-rxjava2:2.0.0-beta3"
in place of
implementation "com.airbnb.android:mvrx:2.0.0-beta3"
in dependencies section of your build.gradle.
Your feature code must be in a Fragment (that extends BaseMvRxFragment), not in an Activity.
Because you have other com.airbnb.mvrx. references that have resolved correctly, it means you do have a reference to the com.airbnb.mvrx library. However, it is likely that you have a different version of the library referenced than the sample's original author. Look in your build.gradle file for dependencies and see if you have the library referenced there. If so, compare its version to the one in the sample, if different, then modify your reference to the sample's version number. If not, then add a reference to the library with the appropriate version number of the library where that object exists.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.airbnb.mvrx:mvrx:12.0.1'
}

Error: cannot find symbol class DaggerAppComponent

I downloaded several sample projects from github that use dagger, e. g. Moxy sample project (trying to run github-sample) but everywhere there is the same error - «cannot find symbol class DaggerAppComponent». I did not make any changes in the projects just downloaded and tried to run them.
Gradle version - 3.1.2
AndroidStudio – 3.3
def dagger = '2.7'
implementation "com.google.dagger:dagger:$dagger"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger"
Does anybody has an idea how to fix it?
Adding the below dependency.
implementation 'com.google.dagger:dagger:2.x'
annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
OR try this
annotationProcessor 'com.google.dagger:dagger-compiler:2.12'
This may not be directly related to what the original poster was looking for but posting this answer for anyone looking to solve a similar error. If you have converted some of your classes to Kotlin then use kapt instead of annotationProcessor in your build.gradle. It is kind of obvious looking back but took me a while to figure out why I'm getting the sysmbol not found error with DaggerAppComponenent without any other details.

WorkManager: Dependency Issue with Kotlin

I'm getting the following error while trying to use Work Manager. I've migrated my project to AndroidX and all other architecture components are working.
def work_version = "1.0.0-alpha02"
/* Work Manager for Background Tasks */
implementation "android.arch.work:work-runtime:$work_version"
implementation "android.arch.work:work-firebase:$work_version"
I'm quite sure I need some dependencies from the Support Library. But I have no clue which one's they are.
I've tried adding the annotations package since the error says it can't find a class file for RestrictTo$Scope. Still doesn't work.
implementation "com.android.support:support-annotations:28.0.0-alpha1"
You are including a reference to the wrong support library, you want the androidx one.
androidx.annotation
Look in
AndroidX refactoring
you will find
androidx.annotation:annotation:1.0.0-alpha1
to correspond with
com.android.support:support-annotations
Make sure that you have only libraries for one or the other kind in your dependencies (project wide).

Importing projects and libries into android studio for dummies?

I'm trying to import this as a library in a project I'm working on in Android Studio:
https://github.com/d4rken/myolib
I cant workout exactly how to do it. even before I try to do this, I tried to open the project using new->Import project-> (selecting the settings.gradle). This then complained about not knowing about:
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
So I tried adding these manually using the advice on:
Importing github projects as library to existing project
Adding external library in Android studio
But its still complaining about no cached version for offline mode. If I do disable work in offline mode then, well it just sits there forever. I want to give it everything manually because in my experience disabling work in offine mode usually doesn't help.
I completely understand this isn't a new topic on Stackoverflow. The issue of how best to import libraries as .jar, .aar, .os etc. etc has been covered a few times. And yet most answers are subtly different and some work sometimes, others work other times.
Does anyone know of a detailed explanation about how I should achieve this ?
If anyone has been successful in importing this project and using its libraries I will be eternally grateful if you could tell me how you achieved such wizardry.
You import the library through your app's build.gradle file. An import section looks something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.1.1'
compile "com.android.support:support-v13:24.1.1"
}
So to import the library you just linked, you would simply add this line to your dependencies section, as per the readme:
compile 'eu.darken.myolib:myolib:0.0.4'

Import statement for dagger cannot be resolved

I am 'lucky' to have been charged with maintaining a program developed by someone else, and I come across the following problem with an import statement:
import com.fizzbuzz.android.dagger.InjectingDialogFragment;
which Android Studio cannot resolve. I am totally new to dagger...
I have the following in build.gradle dependencies:
compile 'com.fizz-buzz:fb-android-dagger:1.0.1'
compile 'com.fizz-buzz:fb-android-bluetooth:1.0.3'
InjectingDialogFragment is not available in the version you are currently using. Please use compile 'com.fizz-buzz:fb-android-dagger:1.0.3' instead.
For better understating on how Dagger works you can use this blog http://antonioleiva.com/dagger-android-part-2/

Categories

Resources