Generate kdoc and watch in browser - android

I don't know how to watch the generated kdoc in my Browser.
I'm developing for Android with Kotlin and added dokka as dependency in gradle.
The new dokka Task runs without Errors.
I added dokka as dependency in my Projects build.gradle
dependencies {
...
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.13"
}
and applied the plugin in my apps build.gradle
apply 'kotlin-android'
apply 'kotlin-android-extensions'
apply 'org.jetbrains.dokka'
But I can't find the Output in the Project Folder.
How can I watch the Output in my browser or where is it?
Thanks
Edit 1: IDE: Intellij; Kotlin Version: 1.1.1
Edit 2 (11.04.2017):
build.Gradle:
dokka {
outputDirectory = "$buildDir/docs"
}

You can control the output directory via the dokka task:
dokka {
outputDirectory = "$buildDir/docs"
}
To generate the docs, run ./gradlew dokka
I've only done this for non-Android projects, but I believe the process is the same.

I got it to work.
This post solved the problem.
Apparently dokka is not able to pick up the sourceSets {...} defined in the android {...}-block.
Workaround:
duplicate the sourceSets{...} outside the android{...}-block

Related

gradle withJavadocJar() and withSourcesJar() for android library

Is there a way to leverage the new functions withSourcesJar() and withJavadocJar() for Android library projects? Currently when I try to use it I get:
> SourceSet with name 'main' not found.
With the latest Gradle version 6.0.1, there seems to be no way to use these new methods in Android library projects. Here’s why I believe that’s the case:
The two methods withJavadocJar() and withSourcesJar() on the java extension have the default main source set hardcoded, see here and here.
There are two methods with the same names (withJavadocJar() and withSourcesJar()) which can be used in feature variant declarations. However, it seems that Android Gradle builds don’t use feature variants, i.e., these methods can’t be used either.
The documentation states, that these come from the JavaPluginExtension - but not from Android DSL. So they can only be used in conjunction with apply plugin: "java" or apply plugin: "java-library", but not with apply plugin: "com.android.application", apply plugin: "com.android.library" and alike. The name of these tasks also suggest that it's common Java (*.jar) and not Android (*.aar). On Android, this would only make sense for a *.jar library, which uses pure Java features, but no Android features at all (which is limited in functionality).
In short, apply plugin: "java-library" would permit accessing these.
With Gradle 7.2 I "recreated" withJavadocJar and withSourcesJar using Gradle Kotlin DSL:
val sourceFiles = android.sourceSets.getByName("main").java.getSourceFiles()
tasks.register<Javadoc>("withJavadoc") {
isFailOnError = false
dependsOn(tasks.named("compileDebugSources"), tasks.named("compileReleaseSources"))
// add Android runtime classpath
android.bootClasspath.forEach { classpath += project.fileTree(it) }
// add classpath for all dependencies
android.libraryVariants.forEach { variant ->
variant.javaCompileProvider.get().classpath.files.forEach { file ->
classpath += project.fileTree(file)
}
}
source = sourceFiles
}
tasks.register<Jar>("withJavadocJar") {
archiveClassifier.set("javadoc")
dependsOn(tasks.named("withJavadoc"))
val destination = tasks.named<Javadoc>("withJavadoc").get().destinationDir
from(destination)
}
tasks.register<Jar>("withSourcesJar") {
archiveClassifier.set("sources")
from(sourceFiles)
}
Put this into your gradle.build.kts file and then run ./gradlew withJavadocJar and ./gradlew withSourcesJar (or use the tasks to create artifacts for publishing).
android.sourceSets.getByName("main").java.getSourceFiles() is the Android specific part to retrieve the "main" source files.

3rd-party Gradle plug-ins may be the cause

After updating to Android Studio 3.1 I got this error message:
The project works fine and this is mostly just a warning, so my question is what's the meaning of the warning and how can I get rid of it?
The relevant parts from gradle files:
This is my project's build.gradle
buildscript {
ext {
kotlin_version = '1.2.31'
anko_version = '0.10.4'
room_version = '1.0.0'
support_version = '27.1.0'
firebase_version = '12.0.0'
gms_version = '12.0.0'
}
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
}
}
And this is my app's build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
To solve the issue, remove Instant App Provision from the "Run Configurations" and leave only the Gradle-Aware Make.
Run -> Edit Configurations..
I have AndroidStudio 3.1, Gradle Plugin 3.1.0 and Kotlin library version 1.2.30.
I restarted Android Studio and the problem disappeared.
Click File -> Invalidate Caches/Restart
Every time I change the gradle file, I must restart Android Studio to or the problem returns.
You can also try this:
Re-ordered repositories to:
mavenCentral()
maven { url 'https://jitpack.io' }
google()
jcenter()
Clearing this folder: user's ~/.gradle/caches and deleting app
build folder manually, then clean and rebuild.
What fixed the issue for me:
Change gradle plugin version to 3.1.0
Change Kotlin version to 1.2.30
Then Android studio changed gradle wrapper to version 4.4
Then Android studio was saying that the build tools version used was
27.0.3 and that I should change it to 27.0.3 so I also changed the target SDK to 27
I added this to my gradle.build:
kapt {
generateStubs = true
}
I hope it helps
at android studio v3.1.2 , happen Error:
Folder D:\AndroidProjects\app\build\generated\source\kaptKotlin\debug
Folder D:\AndroidProjects\app\build\generated\source\kaptKotlin\release
3rd-party Gradle plug-ins may be the cause
because dataBinding use apply plugin: 'kotlin-kapt' so add
kapt {
generateStubs = true
}
Change gradle plugin version to 3.1.2
Change Kotlin version to 1.2.30
Then Android studio changed gradle wrapper to version 4.4
Then Android studio was saying that the build tools version used was
27.1.1 and that I should change it to 27.1.1 so I also changed the target SDK to 27
Here are some steps that I've followed. In my case it's fixed the issue!
Platform modules targeting Android
The update of the experimental multiplatform projects feature introduces support for Android platform modules. These modules should apply the corresponding plugin in the Gradle build script and can use the shared code from a common module:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-platform-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
// ...
// ...
Kapt diagnostic locations
As of now, kapt, the Kotlin annotation processing tool, can offer links to locations in the original Kotlin code rather than generated Java stubs as it reports errors encountered during annotation processing. You can enable this feature by adding these lines to the Gradle build script (build.gradle):
kapt {
mapDiagnosticLocations = true
}
Add this:
allprojects {
repositories {
jcenter()
google()
}
}
Don't forget the next:
// Architecture Component - Room
implementation "android.arch.persistence.room:runtime:1.1.0-beta1"
kapt "android.arch.persistence.room:compiler:1.1.0-beta1"
// Lifecyles, LiveData and ViewModel
kapt 'com.android.databinding:compiler:3.1.0'
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.1.1"
// alternatively, just ViewModel
implementation "android.arch.lifecycle:viewmodel:1.1.1"
// alternatively, just LiveData
implementation "android.arch.lifecycle:livedata:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
// Room (use 1.1.0-beta1 for latest beta)
implementation "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"
// Paging
implementation "android.arch.paging:runtime:1.0.0-alpha7"
// Test helpers for LiveData
testImplementation "android.arch.core:core-testing:1.1.1"
// Test helpers for Room
testImplementation "android.arch.persistence.room:testing:1.0.0"
Clean your project
Build and That's it!
Add all of this, Clean your project, build and That's it! :) Let me know if this works! (If it is not working for you, I will help you with another solution)
More Info: Android Site
:) Let me know if it works! (If it does not work, I will
try to help you finding a better way)
If you give a downVote explain why
What actually helped for me is adding this
kapt {
generateStubs = true
}
into build.gradle
Try removing Instant run from settings and gradle will good to go.
It worked for me.
Here are some steps that i have followed and it's fixed the issue in my case.
First of all install kotlin plugin version to '1.2.31' and update it in build.gradle file like below.
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$1.2.31"
}
Clean Project.
Finally Rebuild the project.
In my case none of the above solutions solved my problem, I was using 1.2.50 Kotlin version without any mention to Instant Run, and the build wasn't generating the Dagger classes, so I find out this question that solved my issue, apparently, in my situation it's an issue related to the new Kotlin version, so I downgraded to version 1.2.41 and worked fine.
By the way, I just tracked to that point because I used the Toggle View on Build screen.
1:Select the Toggle View and build your project
2:You're going to be able to see exactly what happened
Stackoverflow question:
Kotlin 1.2.50 asks for baseFeatureInfoDir
Issue tracker:
https://issuetracker.google.com/issues/110198434
remove apply plugin: 'kotlin-kapt'
add mavenCentral() in build.gradle like:
allprojects {
repositories {
mavenCentral()
google()
jcenter() } }
Sync and Clean project
Here is the some approach how I fix this issue for my case:
First of all update your android gradle plugin version from project build gradle file and then update your gradle version from gradle properties.
Finally update your kotlin version(Mandatory) to kotlin_version = '1.2.30' or later from project build gradle file.
Now try to clean your project and build. Issue should be resolved.
Each time after build if you build again then probably issue will occur again so, just clean your project again and then build.
This happens because the Kapt annotation processor uses this directory to store Kotlin generated files. Android currently does not recognize the path by default.
See Further Details
Adding another answer for those who could not remove Instant App Provision, because it keeps reappearing.
Build the project manually: ./gradlew assembleDebug
It is a hotfix, but it will work (because the issue is probably related to Android Studio).
I had this issue when using Realm with kotlin in android studio.
To solve follow these steps :
After adding Realm to project build.gradle, Make sure your app build.gradle file is like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
.
.
.
androidExtensions {
experimental = true
}
Use kapt instead of annotationProcessor in your app build.gradle dependencies.
Go to Run -> Edit Configurations.. and remove Instant App Provision option.
Run this command in Android studio's terminal :
gradlew assembleDebug
It's OK !
Note: If you see "3rd-party Gradle plug-ins may be the cause" message again, Do step 3 & 4 again.
Configuration on demand with Gradle 4.6 and above: If you're using
Android Gradle Plugin 3.0.x or 3.1.x with Gradle 4.6 and above, you
should disable configuration on demand to avoid some unpredictable
build errors. (If you are using Android Gradle Plugin 3.2.0 or higher,
you do not need to take any action to disable configuration on
demand.)
Disable configuration on demand in your gradle.properties file as
shown below:
org.gradle.configureondemand=false To disable configuration on demand
in the Android Studio settings, choose File > Settings (Android Studio
Preferences on Mac), select the Compiler category in the left pane, and clear the Configure on demand checkbox.
In Android Studio 3.2 Beta 1 and higher, the options for enabling
configuration on demand have been removed.
Please read known issues section from below link.
enter link description here
Actually,I was also facing the same error.
What i did is updating my kotlin version to the latest.
This may resolve Your problem.
Well, I found it is because of apply plugin: 'kotlin-kapt',if you delete this line in build.gradle(app), then you will build successfully...
Have no idea why this plugin results in these warnings.

How to get source code of Android Library directly when using gradle as android build system

How to get source code of Android Library directly when using gradle as android build system?In fact the sourcecode.jar and javadoc.jar should be on the center repository,but I can hardly find a easy way to get them in my Android Studio.
Try adding the following to the "build.gradle" file
apply plugin: 'idea'
idea{
module {
downloadJavadoc = true
downloadSources = true
}
}
For more details on the plugin see: http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html

Error:(2, 0) Plugin with id 'android-test' not found

I am trying to implement Android-DirectoryChooser in my app, but I am new to Android Studio and I have come to a problem that I am not sure how to resolve.
I have created a new folder inside my project called "libraries" and I have copied this library project inside this folder. I then added a dependency like this:
compile project('libraries:android-directorychooser')
I then synced gradle and I have gotten the following error:
Error:(2, 0) Plugin with id 'android-test' not found.
This is probably the problematic line in the project library build.gradle file:
apply plugin: 'android-test'
I've searched for a plugin named "android-test" but I've only found a library and it seems to be deprecated. How can I solve this?
Know you for what this plugin is necessary? When not remove it and your robolectric dependencies.
Plugin comes from https://github.com/robolectric/gradle-android-test-plugin
Robolectric is for unit tests, when you like to use it.(which I would recommend) then just add something like that
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+'
}
}
to your lib module build.gradle file and the plugin should be found
Android-test is no longer a separate plugin. The standard 'android' plugin now includes testing features. See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing for more information.

Convert existing project to library project in Android Studio

How can I convert an existing Android project into an Android library project in Android Studio? In Eclipse, that is possible.
Actually, I want to convert an old Android project into an Android library project so that I can use existing code of that Android project to build a new Android project with minor changes in Android Studio.
In your module's build.gradle file (not the root project, if you use modules!), simply replace:
apply plugin: 'com.android.application'
// or, if you're on an old version
apply plugin: 'android' // note: this one is deprecated
...with:
apply plugin: 'com.android.library'
// or, if you're on an old version
apply plugin: 'android-library' // note: this one is deprecated
Note that recently, 'android' has changed to 'com.android.application', while 'android-library' has been changed to 'com.android.library'. Avoid using the old names in new projects.
After updating your build.gradle file, you should Sync Project with Gradle files (which is in the toolbar), as not doing it might result in errors and things not working correctly.
Android Studio will then update some files to indicate that the module is now a library; as this will be added into your .iml file:
<option name="LIBRARY_PROJECT" value="true" />
As you might already know, you will not be able to run your (now) library project -- you will need to include it into an app project.
If you're using Android Studio 1.0 and you are getting “Library projects cannot set applicationId”, make sure you do not have applicationId in your Gradle build file.
Looking at this document
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup
I think all you have to do is add this to your build.gradle file,
Creating a Library Project
apply plugin: 'android-library'
From the link
Creating a Library Project
A Library project is very similar to a regular Android project with a few differences.
Since building libraries is different than building applications, a different plugin is used. Internally both plugins share most of the same code and they are both provided by the same com.android.tools.build.gradle jar.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 15
}
Changing to Library
Goto android project, where you need to change as Library module.
In build.gradle(:app) file,
change this line to
plugins {
id 'com.android.application'
}
to
plugins {
id 'com.android.library'
}
Delete the line for the applicationId in same build.gradle(:app) file
defaultConfig {
applicationId "com.project.example" //remove this line
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Now Sync Project with Gradle Files.
open project in file explorer,open project.properties and try changing android.library=true in project.properties
This is a late response, but I've been trying to do the same thing. None of the above seem to have done the job for me, but I found this that I think works:
Right click on the project name -> Mark Directory As (at bottom) -> Sources Root
I don't know the difference between Resources Root and Sources Root, and a bit of googleing to turn up the answer, but hopefully that's right. I just know a Library isn't supposed to build an apk, and after setting this option, it's not able to so I'm assuming it works.
If anybody else knows more than me, please say so!
If you make it with command line, like chanakya propose, you have to update it with:
android update lib-project \
--target <target_ID> \
--path path/to/your/project
see: http://developer.android.com/tools/projects/projects-cmdline.html#ReferencingLibraryProject
That work for eclipse, but not for android-studio since that update the build.xml.

Categories

Resources