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
Related
I created an application with kotlin multiplatform and I want now to use flutter to develop the UI once. I followed the tutorial to integrate flutter in an already existing Android app and I choose option B to compile everything in one step.
The first trouble is including the Flutter module as a subproject in the host app: in the kotlin multiplatform project, I have to rename the settings.gradle.kts to settings.gradle. Then I have another error I can't get rid of: Caused by: java.lang.AssertionError: Project :app doesn't exist. To custom the host app project name, set 'org.gradle.project.flutter.hostAppProjectName=<project-name>' in gradle.properties.. Expression: (appProject != null). Values: appProject = null
I understand what the error means: with kotlin multiplatform, the project is not called app but the name of the app, in my case MusicTraining. So as mentioned in the kotlin documentation:
Tip: By default, the host app provides the: app Gradle project. To change the name of this project, set flutter.hostAppProjectName in the Flutter module’s gradle.properties file. Finally, include this project in the host app’s settings.gradle file mentioned below.
So, in the flutter module's gradle.properties file I tried to add the lines:
flutter.hostAppProjectName="MusicTraining"
flutter.hostAppProjectName=":MusicTraining"
I still have the same error.
I tried with vscode to change all instances of :app to :MusicTraining but nothing works. I still have the same error.
As the error mention, I tried to add the line
org.gradle.project.flutter.hostAppProjectName="MusicTraining"
org.gradle.project.flutter.hostAppProjectName=":MusicTraining"
in the flutter module's gradle.properties file, but still the same error.
How can I integrate a flutter module in a kotlin multiplatform app?
Try to add flutter.hostAppProjectName=MusicTraining into gradle.properties file with both Flutter module and you root project.
Notice: run you native application, If you run main.dart, you still get this error
I face the same problem, this works for me.
If you already have a Kotlin multiplatform project, I'd use Jetbrains Compose multiplatform instead of Flutter. Compose is very similar to Flutter and you would avoid the technology split.
https://www.jetbrains.com/de-de/lp/compose-mpp/
I try to create a new Android Studio Project.
Till today creating new projects was done by a simple dialoge window in which you had to determine the project name and the minimal API Level. After doing that the project structure opened and a MainClass and a layout file had already been created.
Now there is a window where you have to determine whether it should be created by Gradle or be just a simple Java Project.
OK it may be an update... Now the strange part starts...
I now get asked to enter an artifactId and a GroupId. (Is this an equivalent to the project name?)
After another new but less confusing window the project was created but the Project structure has changed:There was no module "app", there was altough a Java directory existed no (usually autocreated) Main class or layout file.
(Project structure and the non existing Mainclass can be seen in the picture)
When trying to open an existing project the IDE throws two errors saying that there was no File named "name of the project".iml and app.iml.
I have already tried to reinstall Android Studio.
Is this an update?
Did I mess up settings?
Solved it by deleting not just android studio in system settings but also in registry.
After reinstallling it finally worked.
Thanks for your help
There is a window where you have to determine whether it should be created by Gradle or be just a simple Java Project... I now get asked to enter an artifactId and a GroupId.
Sounds like you made a Gradle project, not an Android app.
The new useless project structure
Maybe useless for an Android project, not a plain Java codebase.
Did I mess up settings?
Possibly. The Android IntelliJ plugin may not be loaded properly
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
I want to use RoboSpock for Testing my android apps, but I am stuck setting up my project. I created an example project which I have added to github.
https://github.com/DerSchimi/RoboSpockExample
This project contains a folder called AppLibrary which is an android-library. The App itself is inside the folder App.
All RoboSpock Tests should go inside the folder AppTests. I have configured everything, but when I try to run my tests I get this error message:
WARNING: no system properties value for ro.build.date.utc
groovy.lang.MissingPropertyException: No such property: AppActivity for class: de.derschimi.app.MainActivitySpecification
at de.derschimi.app.MainActivitySpecification.Should say hello world(MainActivitySpecification.groovy:15)
This is the line of code:
def mainActivity = Robolectric.buildActivity(AppActivity.class).create().get()
Is there anybody out there who is using RoboSpock? Thanks a lot for your help!
The plugin I consider as deprecated. At this moment I'm creating just samples how to enforce gradle java plugin understand the android one. I suggest to browse this project.
https://github.com/pjakubczyk/robospock-sample/tree/master/simple
I am working on a custom Android library. I start off with a java project (in Eclipse) with another UI testing Android project.
In my UI testing project, I reference the library project in build path, and everything is good and I can test the library codes in the UI.
Later on, I decided I need to have the 'Gen' code (for custom styles attributes), so I try to change my library to an Android project (via Android-tools -> convert.. ), and disasters happens! After fixing up all the compile time problems, it finally 'let' me start the UI testing application, and bangs! When I try to create any objects from the library class, it said (in the Log) that Class not found.
Two questions:
Any idea how to fix this? I tried but seems it is for referencing another .apk that need to install separately.
If I just keep it to be java project (not android) for my library, can I use the resource generator? and how?
PS: the dependency (my library) is installed before the UI test application, according to the Console of Eclipse said.
Update: I tried to compile the library project to jar and reference it from the UI testing, and in this way, it works. But I don't want to use this approach since it is very slow in terms of testing.
for those who are doing same mistake like me
when library project is an android project
got to
properties > android > click add button at bottom of the popup inside
library section
and add project, instead of
properties > java build path > project > add
later approach is for pure java projects only .
Finally I found the answer to my own question. This is actually mentioned in official documentation.