How to Configure AspectJ in Android Studio - android

I am trying to configure AspectJ in Android Studio. But after all trial and error its not working ! Surprisingly I am able to make it work with Eclipse Kepler version The steps I followed for Android Studio
Created sample Android Project
File > Settings > searched for AspectJ in Plugin section
Assuming nothing more to be done in Studio , except configuration of build.gradle files
Added compile 'org.aspectj:aspectjrt:1.8.1' to the to the build.gradle (Module:app)
Created Analytics_onBackPressed.aj for back button press detection
Created Analytics_OnClick.aj for click events detection
Created Analytics_onCreate.aj for components oncreate event detection
Created necessary dependency classes which the above mentioned *.aj classes will internally call
Added required permissions in Manifest
Running the project is not detecting any of the events (button click, oncreate or back button click)
Followed these links ReferenceLinkOne , ReferenceLinkTwo and ReferenceLinkThree
My Question is what is more required to make AspectJ working with Android Studio
Steps followed in Eclipse and got AspectJ working
Downloaded Eclipse Kepler version
Through Install New Software option searched for http://download.eclipse.org/tools/ajdt/43/update
Installed AspectJ Development Tools (Required) .
Created sample android project
Created Analytics_onBackPressed.aj for back button press detection
Created Analytics_OnClick.aj for click events detection
Created Analytics_onCreate.aj for components oncreate event detection
Added required permissions in Manifest File
Right clicked in project and converted project to AspectJ by the following
Configured Java build path with AspectJ runtime library
Now while running the project, I am able to detect components oncreate, back button press
Environment Used
Android Studio : 2.1.2
JRE : 1.8.0
Windows 7 Enterprise
Any help is highly appreciated!
EDIT : 1 , From the output , still AspectJ is not properly configured
As per this link , I created jar file from eclipse including *.aj files and corresponding dependency. Excluded AndroidManifest.xml while creating jar file and created jar
Created Project in Android Studio. Placed this *.jar file in libs file. (apps> libs). I have enabled AspectJ waving as shown below
Now searched the properties for AspectJ and enabled
Now running the project, should be creating logs I had put in *.aj files which is in plugin . Unfortunately these logs are not printed in Android Studio logs.
Form which I am concluding still AspectJ is not enabled in this project OR there is a configuration error

Disclosure: I am the author of the inofficial AspectJ weaver plugin.
As noted in the AspectJ weaver plugin documentation, the plugin does not support compiling .aj files.
To use this plugin, you have two options:
Switch from .aj to annotation style aspects.
Compile the .aj files outside the IDE (IntelliJ Community / Android Studio), for example using Maven/Gradle/Ant, and package them into a .jar. Include this .jar as a dependency in your project and click the Search for aspects... button, as per the documentation.

I have had various success trying to get AspectJ working in Android Studio. This link helped me get part of the way there (assumes Gradle build setup for your project). http://fernandocejas.com/2014/08/03/aspect-oriented-programming-in-android/
Using the custom block of code in the build.gradle file, I was able to get aspects defined using annotations in .java files compiling and weaving properly in my project. However, this same method did not work for me when defining native aspects using .aj files. I hope it helps.

IntelliJ has no tooling support for AspectJ, and Annotation Style AspectJ can work on Android studio. Just treat the aspect code as Java code.
For detail read this issue
aspectj for Android studio - where is AJDT plugin
Also, you can use gradle plugin aspectjx which can weave kotlin code and demo is here

Related

How to create an android project using Kotlin DSL and buildSrc

I have searched a lot and I can only find guides or results that tell you how to migrate an existing Android project that uses the normal groovy layout that is default into a project with Kotlin DSL and buildSrc. I was wondering if there is a way to create an android project that was rather than having to migrate it.
The only thing I can think of is someone creating a github action for you to fork, but I would rather be able to create one from Android Studio itself.
Using the terminal in Android Studio, navigate to a new folder (this is where the project will be saved) and type the following:
gradle init --type kotlin-application
Press [CTRL + ENTER] to have Android Studio process the command. The run tab at the bottom should open and will ask which DSL you would like to use for the project. Click the area after this text and enter 2 for Kotlin. Then enter your project name and package name.
I would still recommend using the standard GUI interface within Android Studio to create a project and manually convert the files, as the method above does not create all the standard files that Android Studio does. In other words, you will likely find it more time consuming using the Build Init Plugin.
reference: Build Init Plugin

How do I add in a class created in a different android project?

Please forgive the vague sounding title
I am trying to get this project to compile in android studio:
https://proandroiddev.com/how-to-create-a-bubble-selection-animation-on-android-627044da4854
https://github.com/igalata/Bubble-Picker
Downloading the github project and compiling it as it is did not work, I am getting this error, and redownloading dependencies and syncing as suggested in the error message did not work
UPDATE: I have upgraded android studio, gradle and kotlin plugin to latest version and it's still the same problem.
I can use the library version of this project just fine, using the steps described in the github page. I want to compile the source code of this component together with my project so that I can tweak the bubble animation itself. Since the github project itself does not compile, I created a Hello World project first, then manually copied in the bubblepicker folder in the Hello World project. Inside the bubblepicker folder, I changed the name of the folder tree java/com/iglata/bubblepicker to java/com/test/app/bubblepicker, and changed the package name of the files inside this folder to reflect this. I then copied the code in DemoActivity.kt to my MainActivity.kt and changed the package names and made few minor adjustments to make the compiler errors go away.
I have made some modifications in the gradle files as well so that gradle syncing does not give any errors. However, anything inside bubblepicker does not seem to be detected in the MainActivity.kt, or it's activity layout xml file. For example,
import com.test.app.bubblepicker.BubblePickerListener
is marked with red colour in android studio and the error is unresolved reference. If I remove all references to bubblepicker and replace the code in MainActivity.kt with the Hello World code, then it compiles and runs fine, so it's as if bubblepicker is not getting picked up by the compiler at all.
What could be the problem here?
Or at the very least, how can I compile the bubblepicker github project? Simply loading the whole project in Android Studio is giving me compiler errors. I am doing this on Android Studio 3.5 on macOS with Kotlin version latest as of September 4.
I didn't get any error while import Github project.
Kindly update your android studio and kotlin Gradle version and check same.

Include External Source Code Library for Android Studio 1.4.1

I'm attempting to create an Android app with Android Studio that uses source code from:
https://github.com/mapbox/mapbox-gl-native/
I will need to modify the source code, build and debug the changes, and commit those changes back to the forked repository I've made from mapbox-gl-native.
It appears much of the library code is in C++, while the project that uses the code will be in Java (if that makes a difference).
I've tried a bunch of things (mostly ignorant) and keep getting the following message:
Gradle 'name' project refresh failed
Error: Configuration with name 'default' not found.
Newbie on Android Studio, so please be as descriptive as possible. I'm using Android Studio 1.4.1, as other similar questions seem to have version specific answers.
Is there a description on how to set up an Android Studio project to include source code and how to structure such a project?
or
Can you tell me what the message means and how to fix it?
Thanks.

Problems converting to library project including Facebook SDK

I have a working app that I've now converted to being a library project in Eclipse. When I attempt to include the library as a "Project Reference" in an empty app (no other functionality other than what it inherits from the library) it fails to build. I get the message Unable to execute dex: Multiple dex files define Lcom/facebook/android/R$attr;.
To try to work around this I tried to delete the Android Dependencies completely. But then I get a "Class not found exception" for classes in the library.
Is it possible to remove the Facebook dependency without also removing the app library dependency? I tried to delete the facebooksdk.jar file but was unable to do so since all the buttons are grayed out. (see screen capture below)
I also tried simply unchecking "Android Dependencies" in "Order and Export". That had no effect on the problem.
Your suggestions are welcome.
FYI, my project has 3 main components. All 3 are contained in the same Eclipse project folder (see screen capture):
Application "App_A"
Library_L (included as Project Reference in "A") It's worth noting that Library_L executes perfectly when I run it as a non-library project.
Facebook SDK 3.0.2 (included as Project Reference in Library_L (see screen capture)
Project References are used to include a library project (e.g., the Facebook SDK).
The documentation -- and books by balding guys -- show you how to attach an Android library project to your app, and it has nothing to do with "Project References".
Similarly, the documentation for the Facebook SDK shows you how to attach their Android library project to your app (see Step 6). They follow the standard Android library project approach, and that too does not involve "Project References".
Now, it is conceivable that there's something about a newer Eclipse version (I'm running Indigo) that causes "Project References" to show Android library projects as checked -- it does not do so in my version.
Make sure that you have properly set up the Android library projects, and see if that helps with your issue.

Can not include source library in project in Intellij IDEA

I've created library project in IDEA with common helpers, which I use in my android applications.
Then I've created android application and included in it my library project like this tutorial said.
Everything seemed okay, code autocomplete worked fine, IDEA recognize that library and all classes and methods in it.
But then I compiled application and saw error "'org.my.helperlibrary' does not exist". However as I said IDEA acts like everything okay before making/launching project.
Here is similar question, but answer is trivial, of course my library has checked "Is Library Project" option but I still can not launch my application which use my library.
Updated:
I've just saw an error: "UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lorg/my/helperlibrary/Helper;" when I removed all usages of library in my android application. So it's just included in my app and not used.
It turned out that I should not add dependency manually in that window
I rather should add new module in my Project window at the left
Then I should choose iml file in the root folder of android library project I want to use
Then I pressed finish and from that point I had two modules in my project
After that when using classes I can press Alt+Enter on any class from SampleLibrary and tell IDEA to add module dependency
Then I could see that IDEA made all I need without me. I can now use SampleLibrary from SampleApplication!
Try to select library project, then click Build -> Compile <your library project name>.
Then back to you project which use this library and click Build -> Rebuild Project.
After that try to run project again.
Hope it helps.

Categories

Resources