I can not find any documentation on how to configure my Gradle file to create the JavaDoc for my project. I already tried some snippets from SO and blog articles but none of them seem to work or they do not provide context.
This is my Gradle file. What do I need to do to add a task to generate JavaDoc?
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
In our projects we added the following to the app's build.gradle:
android.applicationVariants.all { variant ->
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.links("http://d.android.com/reference/");
}
}
This will add tasks to the build of the form generate<build_variant>Javadoc. So let's say you have a free and a pro version of your app, this would add tasks like:
generateFreeDebugJavadoc
generateFreeReleaseJavadoc
generateProDebugJavadoc
generateProReleaseJavadoc
Hope this helps
In android studio, write a gradle task of type Javadoc :
task createJavadocs (type: Javadoc)
{
source = project.android.sourceSets.main.java.srcDirs
options.linkSource true
classpath += project.files(project.android.getBootClasspath().join(File.pathSeparator))
failOnError false
}
Simply execute this task will create javadocs.
Related
I am learning Gradle for Android recently. For learning impressively, i create all android application files manually.
my project dirs as below
package name : com.wonbin.gradledemo
project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
app module build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.wonbin.gradledemo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "adroid.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
lintOptions {
htmlReport true
htmlOutput file("lint-results.html")
}
}
dependencies {
compile fileTree(dir:'libs',include:['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
exclude group: 'com.android.support',module: 'support-annotations'})
compile 'com.android.support:appcompat-v7:23.4.0'
testCompile 'junit:junit:4.12'
}
./gradlew build is successful and there are 'intermediates' and 'generated'
dirs , but no outputs dir, i don't know what to do!
Thanks a lot!
You need not only to build, but to assemble it as well.
To do this you can run a gradle task
assembleDebug
Or use Build -> Build APK main menu item
i want to rename package name using gradle on cmd.because i have multiple project customization and change package name using ide very difficult to change each package name separately.please give me solution.thanks in advance
apply plugin: 'com.android.application'
apply plugin: 'maven'
android {
compileSdkVersion 21
buildToolsVersion "23.0.0 rc2"
sourceSets {
defaultConfig {
applicationId "com.appbell.restaurant.genericresto"
minSdkVersion 14
targetSdkVersion 19
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
main {
manifest.srcFile 'src\\main\\AndroidManifest.xml'
println('android'+manifest.srcFile)
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
task changePackage{
replaceInManifest("com.appbell.restaurant.example","com.appbell.imenu4u")
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
// Make sure this is at least 0.10.+
classpath 'com.android.tools.build:gradle:1.0.+'
}
}
task appStart(type: Exec, dependsOn: 'installDebug') {
// linux
//commandLine 'adb', 'shell', 'am', 'start', '-n', 'com.example/.MyActivity'
// windows
commandLine 'cmd', '/c', 'adb', 'shell', 'am', 'start', '-n', 'com.appbell.restaurant.genericresto/com.appbell.and.resto.and.ui.SplashActivity'
}
dependencies {
compile project(':facebook')
compile project(':stripe')
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/mobileappclasses.jar')
compile files('libs/pgsdk.jar')
}
def replaceInManifest(fromString, toString) {
def manifestFile = "C:\\Users\\Ntin Gorle\\AndroidstudioProjects\\MyApplication\\RestoAppNEw\\src\\main\\AndroidManifest.xml"
def updatedContent = new File(manifestFile).getText('UTF-8').replaceAll(fromString, toString)
new File(manifestFile).write(updatedContent, 'UTF-8')
}
I this code package name change but not reflect in all .java file.please tell me how to change in all .java classes.
If you need to change the package name often and in multiple projects. I recommend the plugin "Android Package Renamer", it's available on the Android Studio plugin market and Intellij IDEA. All you need to do is download it and use it. It works well on many different types of projects.
Usage
Open Your Project.
Click -> File -> Rename Package
Input the Package you want to change.
Click Ok.
Sync Project with Gradle Files or Invalidate Caches
You can see my detailed answer here or head over to the github repo for a closer look at the instructions.
I know this sounds very easy, but android studio is eating my brains out. I know how to import my current project say myProject in to ADT very easily. But I came to know that soon the support for adt will be ending. So i decided to switch to Android studio. I am using the following libraries in my project
Commons
ActionBarSherlock
AndroidImageChacheMaster
SlidingMenuMaster
I tried to import the project myProject.
See its Project.Properties file
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-21
android.library.reference.1=../actionbarsherlocklibrary
android.library.reference.2=../Android-Image-Cache-master
android.library.reference.3=../Commons
android.library.reference.4=../google-play-services_lib
android.library.reference.5=../SlidingMenuMaster
When i tried to import it A.S told me unrecoverable errors and I pasted the library folder as instructed by android studio.
And it project was imported succesfully
but there are two error apparing in the log
/home/mukund/StudioProjects/aftercrash62/commenorkingandroid/build/intermediates/manifests/tmp/manifestMerger2026412193483179673.xml
Error:(5, 5) uses-sdk:minSdkVersion 5 cannot be smaller than version 7 declared in library /home/mukund/StudioProjects/aftercrash62/commenorkingandroid/build/intermediates/exploded-aar/com.actionbarsherlock/actionbarsherlock/4.4.0/AndroidManifest.xml
Error:(5, 5) Execution failed for task ':commenorkingandroid:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 5 cannot be smaller than version 7 declared in library /home/mukund/StudioProjects/aftercrash62/commenorkingandroid/build/intermediates/exploded-aar/com.actionbarsherlock/actionbarsherlock/4.4.0/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.actionbarsherlock" to force usage
please help what is wrong here?
and now my project structure is
actionbarsherlocklibrary(empty)
myProject(manifests,java,res,aidl,resources,c,assets)
androidimagecachemaster(manifests,java,res)
commenorkingandroid(manifests,java,res) // i havent imported anything with this name
commons(manifests,java,res)
Gradle Scripts
build.gradle(Project:myProject)
build.gradle(Module:actionbarsherlock)
build.gradle(Module:myProject)
build.gradle(Module:commons)
build.gradle(Module:androidimagecachemaster)
build.gradle(Module:commenorkingandroid)
gradle-wrapper.properties
settings.gradle
here are my gradle files
build.gradle(Project:myProject)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
build.gradle(Module:actionbarsherlock)
apply plugin: 'java'
build.gradle(Module:myProject)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.five.myApp"
minSdkVersion 11
targetSdkVersion 16
ndk {
moduleName "cr3engine-3-1-1"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':actionbarsherlocklibrary')
compile project(':androidImageCachemaster')
compile project(':commons')
compile project(':commenorkingandroid')
compile 'com.google.code.gson:gson:2.1'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/commons-io-2.4.jar')
compile files('libs/epublib-core-latest.jar')
compile files('libs/slf4j-android-1.6.1-RC1.jar')
compile files('libs/slf4j-android-1.7.5-7-sources.jar')
compile files('libs/universal-image-loader-1.9.1.jar')
compile files('libs/zip4j_1.3.2.jar')
}
build.gradle(Module:commons)
apply plugin: 'com.android.library'
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/actionbarsherlock-plugin-maps-4.1.0.jar')
}
build.gradle(Module:androidimagecachemaster)
apply plugin: 'com.android.library'
android {
compileSdkVersion 10
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/CWAC-AdapterWrapper.jar')
}
build.gradle(Module:commenorkingandroid)
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 5
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
}
If you have added Sherlock as an AAR dep like
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
you can remove
compile project(':actionbarsherlocklibrary'), include ':sherlock' line from your settings.gradle, then related folder from your project.
And your targetSdkVersion can be the same as your compileSdkVersion as well.
I am trying to add Dexguard to Android Studio. I have followed the guidelines so my build.gradle is the following:
buildscript {
repositories {
mavenCentral()
flatDir { dirs '/Users/XXXX/Desktop/DexGuard5.3.00/lib' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.4'
classpath ':dexguard:'
}
}
apply plugin: 'dexguard'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
proguardFile plugin.getDefaultDexGuardFile('dexguard-debug.pro')
proguardFile 'dexguard-project.txt'
proguardFile 'proguard-project.txt'
}
release {
proguardFile plugin.getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-project.txt'
proguardFile 'proguard-project.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Then I try to build the project and I get the following error:
Error:A problem occurred configuring project ':XXXX'.
No such property: baseName for class: com.android.build.gradle.internal.variant.ApplicationVariantData
Has anyone experienced such problem again?
Thank you in advance!
The Gradle plugin for DexGuard 5.3.00 is compatible with the Android plugin 0.5.1, so you should adapt the class path at the top of the file.
You probably want to install the latest version of the Gradle plugin though. At this time of writing, the Gradle plugin for DexGuard 5.5 is compatible with the Android plugin 0.9.0.
As a reference, you can always find working sample projects with build files in DexGuard's samples directory.
First you can try to add nexusUsername=123 nexusPassword=123 in the "project/maven_push.gradle"
Then if it report "Error:Could not find property 'allJava' on source set main."
you can try this:
task androidJavadocs(type: Javadoc) {
// comment it if you find
//source = android.sourceSets.main.allJava
}
task androidJavadocsJar(type: Jar) {
classifier = 'javadoc'
//basename = artifact_id
// comment it if you find
//from android.sourceSets.main.allSource
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
//basename = artifact_id
////comment it if you find
//from android.sourceSets.main.allSource
}
Last it‘s not my answer ,I found it in an small blog~~~Thanks to the authoer ,it sloved my problems~
Good luck to you ~
I am trying to include Otto library in my project, but am getting this error:
> Could not resolve all dependencies for configuration ':maptest:_debugCompile'.
> Could not find com.squareup:otto:1.3.4.
I have tried cleaning project, running Tools -> android -> sync project with gradle files but that gives me the same error.
My build.gradle is the following:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.squareup:otto:1.3.4'
}
You should add maven central repository, so gradle know where so search for library.
repositories {
mavenCentral()
}
Did you import Otto library into Android Private Libraries? Try clean project this way: Project -> Clean...
You may check this out.