Gradle Build does not include Android Annotations Class - android-gradle-plugin

I am using Android Annotations for my Android project. I receive during startup of my App at my device the following exception
12-25 15:23:21.325: E/AndroidRuntime(24714): java.lang.RuntimeException:
Unable to instantiate activity
ComponentInfo{de.myproject.android/de.myproject.android.activity.MainActivity_}:
java.lang.ClassNotFoundException: Didn't find class "de.myproject.android.activity.MainActivity_"
on path: DexPathList[[zip file "/data/app/de.myproject.android-56.apk"],
nativeLibraryDirectories=[/data/app-lib/de.myproject.android-56, /vendor/lib, /system/lib]]
It seems to be that the generated Android Annotations Classes (MainActivity_) are not included in the apk file.
I am using the following Gradle build file
buildscript {
repositories {
jcenter()
mavenLocal();
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25"
defaultConfig {
minSdkVersion 16
targetSdkVersion 20
multiDexEnabled true
}
lintOptions {
abortOnError false
}
testOptions.unitTests.all {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
}
repositories {
jcenter()
mavenLocal()
maven {
url "https://jitpack.io"
}
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile 'com.firebaseui:firebase-ui-auth:1.0.1'
compile group: 'org.androidannotations', name: 'androidannotations', version: '4.1.0'
compile group: 'org.androidannotations', name: 'androidannotations-api', version: '4.1.0'
compile 'com.google.android.gms:play-services-location:10.0.0'
compile ('de.myproejct:myApi:v1-1.22.0-SNAPSHOT') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'com.google.code.findbugs'
}
compile ('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'com.google.code.findbugs'
}
compile 'net.steamcrafted:load-toast:1.0.10'
testCompile 'junit:junit:4.12'
}
The error occured for the first time when I added the following dependency
compile 'net.steamcrafted:load-toast:1.0.10'
to my build file. When I remove this dependency my app works perfect on my device.
So what is wrong with my build file or with Android Annotations?

You should use the AndroidAnnotations depency in annotationProcessor scope.

Related

Default buildDir for kotlin projects

I'm trying to add documentation to my project with dokka https://kotlinlang.org/docs/reference/kotlin-doc.html
I'm not quite able to figure out where the javadocs are located after doing a successful ./gradlew build.
It says there they should be in $buildDir/javadoc but I'm not sure where buidlDir is pointing to.
My build.gradle file is this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
id 'org.jetbrains.dokka' version '0.9.18'
// id("org.jmailen.kotlinter") version "1.23.1"
}
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
}
group 'com.github.me.dynamik'
version '1.0-SNAPSHOT'
apply plugin: 'application'
apply plugin: 'kotlin'
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = 'com.github.me.dynamik.interpreter.MainEntryKt'
repositories {
mavenCentral()
jcenter()
maven { setUrl("https://dl.bintray.com/hotkeytlt/maven") }
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
configurations {
ktlint
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile 'com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3'
// https://mvnrepository.com/artifact/junit/junit
testCompile group: 'junit', name: 'junit', version: '4.4'
implementation 'com.github.ajalt:clikt:1.7.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
run {
standardInput = System.in
}
jar {
manifest {
attributes 'Main-Class': 'com.github.me.dynamik.interpreter.MainEntryKt'
}
}
test {
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'
// Show test results.
testLogging {
events "passed", "skipped", "failed"
}
}
I'd love a pointer or two in the right direction.
Thank you!
In Gradle the project property buildDir points by default to the subdirectory build of your project directory.
The dokka output directory javadoc may be missing in buildDir because the dokka task has never run before. Your build.gradle file seems not to have any dependencies on the dokka task or its output, so it isn't triggered when you're running build or assemble tasks. You can try running it explicitly: ./gradlew dokka or add a dependency on that task to some other lifecycle task, e.g
assemble.dependsOn(dokka)

Kotlin: How to create a runnable jar?

I'm trying to create a runnable jar with Kotlin.
My gradle.build is this:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
}
group 'com.github.dynamik'
version '1.0-SNAPSHOT'
apply plugin: 'application'
apply plugin: 'kotlin'
mainClassName = "interpreter.Repl"
repositories {
mavenCentral()
maven { setUrl("https://dl.bintray.com/hotkeytlt/maven") }
}
configurations {
ktlint
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile 'com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3'
// https://mvnrepository.com/artifact/junit/junit
testCompile group: 'junit', name: 'junit', version: '4.4'
ktlint "com.github.shyiko:ktlint:0.31.0"
implementation 'com.github.ajalt:clikt:1.7.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
run {
standardInput = System.in
}
jar {
manifest {
attributes 'Main-Class': 'interpreter.Repl'
}
}
(As it stands, when I do ./gradlew run, everything works as expected.)
I'm reading an article here on how to proceed, and it says to do: java -jar <MY_PROJECT_NAME>.jar.
I don't quite understand this -- where do we run this? I tried running it from my project root and I got an error:
Error: Unable to access jarfile <my_jarname>.jar
As of Gradle 5.4.1, a build.gradle.kts would need a section like this:
tasks.register<Jar>("uberJar") {
archiveClassifier.set("uber")
manifest {
attributes(
"Main-Class" to "mytest.AppKt",
"Implementation-Title" to "Gradle",
"Implementation-Version" to archiveVersion
)
}
from(sourceSets.main.get().output)
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}
Ok, I figured it out :)
So, the way to create a jar is to go: ./gradlew build. This creates a jar in build/libs.
The problem is, when running that jar, one would run into an exception about java.lang.intrinsics because the kotlin stdlib hasn't been packed into the jar.
While there is a way to manually accomplish that, I found the easiest solution is to simply use the shadowjar plugin.
My build.gradle ended up looking like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
}
group 'com.github.dynamik'
version '1.0-SNAPSHOT'
apply plugin: 'application'
apply plugin: 'kotlin'
apply plugin: 'java'
mainClassName = "interpreter.Repl"
repositories {
mavenCentral()
jcenter()
maven { setUrl("https://dl.bintray.com/hotkeytlt/maven") }
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
configurations {
ktlint
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile 'com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3'
// https://mvnrepository.com/artifact/junit/junit
testCompile group: 'junit', name: 'junit', version: '4.4'
ktlint "com.github.shyiko:ktlint:0.31.0"
implementation 'com.github.ajalt:clikt:1.7.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.0'
}
apply plugin: 'com.github.johnrengelman.shadow'
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
run {
standardInput = System.in
}
jar {
manifest {
attributes 'Main-Class': 'interpreter.Repl'
}
}
When using a Kotlin main class you need to add a Kt at the end of the class name while referencing it on MANIFEST.
So, if your main class is called interpreter.Repl, use:
jar {
manifest {
attributes 'Main-Class': 'interpreter.ReplKt'
}
}
instead of
jar {
manifest {
attributes 'Main-Class': 'interpreter.Repl'
}
}

A problem occurred configuring project ':app'

Getting error when trying react-native run-android.I don't know why I'm getting this error.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApk'.
> A problem occurred configuring project ':react-native-vector-icons'.
> Could not resolve all dependencies for configuration ':react-native-vector-icons:classpath'.
> Could not find any matches for com.android.tools.build:gradle:2.3.+ as no versions of com.android.tools.build:gradle are available.
android\build.gradle is as follows.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is
installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
gradle version: 3.3,
plugin:2.2.3
Upgrade react-native-vector-icons: "^6.0.2" in package.json
Then run npm i react-native-vector-icons
As a last step, cd android && ./gradlew clean.
Change dependencies from:
dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
}
to:
dependencies {
compile "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
}
also change buildscript dependencies to use: classpath 'com.android.tools.build:gradle:2.2.3'
and maven { url "https://dl.bintray.com/android/android-tools/" } instead of google()
So your ../node_modules/react-native-vector-icons/android/build.gradle should look like this:
buildscript {
repositories {
maven { url "https://dl.bintray.com/android/android-tools/" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.library'
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
android {
compileSdkVersion safeExtGet('compileSdkVersion', 26)
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
mavenCentral()
}
dependencies {
compile "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
}

Gradle Failed to resolve: commons-io:commons-io:+

When syncing Android project with gradle in android studio , it fails resolving
the packages shown in the screeshot below .
here's my build.gradle :
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.dmbteam.cityguide"
minSdkVersion 10
targetSdkVersion 22
versionCode 4
versionName '4.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'commons-io:commons-io:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile('org.simpleframework:simple-xml:2.7.+') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile project(':pinterest_lib')
compile('com.crashlytics.sdk.android:crashlytics:2.4.0#aar') {
transitive = true;
}
compile 'com.google.android.gms:play-services-maps:7+'
compile 'com.google.android.gms:play-services-location:7+'
compile 'com.google.android.gms:play-services:7+'
}
under repositories, I usually find that I end up having to have a chain something like this:
repositories {
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
In other words, it 1st tries to use your local maven repo, then the specific maven repo/mirror, and then falls back to jcenter as a last resort.

Crashlytics Error:(11, 0) Plugin with id 'io.fabric' not found compile lib

I am getting the error,
Error:(11, 0) Plugin with id 'io.fabric' not found
when trying to run crashlytics on my project.
I faced the same issue, when tried to use Fabric plugin for android studio(automated code generation by plugin).I followed this documentation also.
And finally, I could see there were some missed lines in build.gradle.
So this is the top level project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'java'
allprojects {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
}
and this is the build.gradle for app module
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "your application package name"
minSdkVersion 10
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:support-v4:22.0.0'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
}
and at last "clean build" and all was set for me.
I ended up creating an empty project and using the plugin on it and then I compared the gradle file and realized that this was not being added
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
in your project gradle file:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'java'
allprojects {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
}
in your app gradle file:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "your application package name"
minSdkVersion 10
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:support-v4:22.0.0'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
}
You just forget to add below mentioned line in Project level gradle file.
maven { url 'https://maven.fabric.io/public' }
Also please add below mentioned line in dependencies (in project level gradle file)
classpath 'io.fabric.tools:gradle:1.26.1'
I think you lost "google()" in repositories of buildscript.
buildscript {
repositories {
jcenter()
google()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'io.fabric.tools:gradle:1.+'
}
}
allprojects {
repositories {
jcenter()
}
}
I have faced this issue while working with Android + Cordova + Angularjs Hybrid project.
apply plugin: 'io.fabric'
By commenting this line at the path /app/build.gradle solved the issue.
Hope it helps someone!!