Android Gradle jar generation - java

I have an Android Project with a working build.gradle file. This is used to build an Android App. Additionally now I'd like to add my server code (plain java) to this project and setup the build.gradle file to run/start the emulator app like normal and also generate a jar file of the server code, which I can deploy onto my server.
I am new to Gradle and Groovy, so I am not sure about how to write the tasks correctly to achive my goal as described above. I'd really apprechiate some help in setting up this build file. I know I'll need the jar and java plugins but can't seem to figure out how to integrate everything into the Android build.
What I have so far in the (working) build file:
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 29
buildToolsVersion '29.0.3'
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = files("${buildDir}/jacoco/testDebugUnitTest.exec")
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// https://mvnrepository.com/artifact/com.esotericsoftware/kryonet
implementation 'com.esotericsoftware:kryonet:2.22.0-RC1'
}

Related

Chaquopy How can I import pattern library?

I would like to import pattern library of python.
The build gradle (app) is like below.
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.chaquo.python'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.chaquopy"
python{
pip{
install "pattern"
}
}
sourceSets{
main{
python{
srcDirs = ["src/main/python"]
}
}
}
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
// Here is local python.exe folder.
python{
buildPython "C:/Users/xxxx/AppData/Local/Programs/Python/Python38/python.exe"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Sync task finished successfully,
but it failed when I build the project, because of the failure to install mysqlclient.
Can I import pattern library using Chaquopy?
I'll appreciate your help.
It looks like Pattern doesn't actually require mysqlclient: in fact, it defaults to using SQLite. So you can modify it to remove the requirement:
Download the sdist from https://pypi.org/project/Pattern/#files.
Extract it.
Edit Pattern-3.6/setup.py to remove the "mysqlclient" requirement.
Create a .zip or .tar.gz file from the modified Pattern-3.6 directory.
Install this file by its filename, as shown in the Chaquopy documentation.

Can't implement firebase dependencies on my android app

i'm developing an Android Studio App and trying to create a user register activity. I already added firebase into the project but when i try to add the firebase database dependencies, the app crashes instantly and not a single error is reported. However, when i remove the 3 implements from the build gradle, it runs correctly. Here i leave both build gradle codes. Thanks.
Build gradle project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.google.gms:google-services:4.3.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build gradle app (this works properly):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.jota02"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//new implements
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
}
Build gradle app (this crashes):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.jota02"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//new implements
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.firebase:firebase-database:20.0.0'
}
SOLVED
The problem just was that i was running an old Android Studio version. I updated Android Studio and checked the gradle versions and now it's all working properly, thanks.
When you use firebase-bom dependency, you no need to mention version for firebase-database and other firebase library.
firebase-bom will choose right version for you or if you want particular version of firebase remove firebase-bom.so add dependency like below
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.0.1')
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-database'

How to fix gradle when this error appear?

I started a new project and put fire-base cloud:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "android.example.com.squawker"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
// RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'
// Schematic dependencies for ContentProvider
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
implementation 'net.simonvt.schematic:schematic:0.6.3'
// Preferences Dependencies
implementation 'com.android.support:preference-v7:28.0.0'
// Firebase dependency
implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
// Apply the Google Services plugin. Make sure to add the google-services.json file in the app
// folder. You download it from the Firebase console
apply plugin: 'com.google.gms.google-services'
and this error apeared:
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
This probably because of apt plugin which is already obsolete. So, you need to remove the following:
apply plugin: 'android-apt'
then change the following:
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
with:
annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.6.3'
Similar to API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders() Happy Coding!

Failed to resolve: com.android.support:appcompat-v7:28.+ , Error: more than one library with package name 'android.support.graphics.drawable'

I'm new to Android Studio, I tried everything to solve this problem "Failed to resolve: com.android.support:appcompat-v7:28.+ "
I tried to clean project , invalidate cash/restart and removing .idea and still the same
I'm using android studio 2.2.1 for a learning reason , and I updated it to android studio 3 and there a multiple rendering problems so I returned back to version 2.2.1
I tried to add
maven {
url 'https://maven.google.com/'
name 'Google'
}
So,It stuck with another problem
"Error:Execution failed for task ':app:processDebugResources'.
> Error: more than one library with package name 'android.support.graphics.drawable'"
Error Photo
Finally I tried to change "appcompat-v7:28.+" to "appcompat-v7:27" and it' works but still tell me that i should use the same library to avoid mistakes
This is my Gradle code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.1"
defaultConfig {
applicationId "com.example.aimlive.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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:28.+'
testCompile 'junit:junit:4.12'
}
Replace 'com.android.support:appcompat-v7:28+' by 'com.android.support:appcompat-v7:28.0.0'
and add below dependencies
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
try adding this to your code:
repositories {
jcenter()
maven { // <-- Add this
url 'https://maven.google.com/'
}
}
Update: Now you moved on to another error:
Error: more than one library with package name 'android.support.graphics.drawable ...
To fix this, you need to change compile to implementation in dependencies part.
if you are using
compileSdkVersion 28
add in your dependencies below code
implementation 'com.android.support:appcompat-v7:28.0.0-alpha'
this is the link
Try this one, hope it is working
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
dependencies
classpath 'com.android.tools.build:gradle:3.1.4'
android
compileSdkVersion 28
minSdkVersion 21
targetSdkVersion 28
Try this code, hope it will be working. Thanks
build.gradle (Project)
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
build.gradle (app)
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "YOUR_PACKAGE_NAME"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies check for implementation
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
I found that 'com.android.support:animated-vector-drawable' and 'com.android.support:support-vector-drawable' have a same package name in support library version 28.0.0. Normally this does not make the problem.
But if you have the following line in gradle.properties
android.uniquePackageNames = true
you will see the error
more than one library with package name 'android.support.graphics.drawable'"
If you should use the uniquePackageNames option, use androidx instead of support library 28.0.0.
In case someone like me stuck for hours and find out the you have to check the maven dependency "com.android.support:appcompat-v7:28.0.0". remove the "+" sign as gradle does not like it for unpredictable versions. so i had to check the maven repository and found that i was compiling with 29 and 29 does not exist. please check below link
[""][1]
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.amirkhan.birthday"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
}
2)) Maven should be included.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}
Wallah the problem is solved
[1]: https://mvnrepository.com/artifact/com.android.support/appcompat-v7/28.0.0

Android Studio 3.0 Unresolved reference: SupportedLanguages for AIConfiguration class in Dialogflow(api.ai)

I am building a chatbot Android app in Kotlin, through queries to a Dialogflow agent. I am using the Dialogflow android client github repository Readme and the sample app provided in that repository as the basis to build the app. As referenced in the above sources, java code for AIConfiguration.SupportedLanguages works fine:
import ai.api.android.AIConfiguration;
.....
private void initService(final LanguageConfig selectedLanguage) {
final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode());
.....
You can find the full usage of this here.
When I am implementing this in Kotlin:
import ai.api.android.AIConfiguration
....
private fun initService() {
//final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode());
val config = AIConfiguration(CLIENT_ACCESS_TOKEN,
AIConfiguration.SupportedLanguages.EnglishGB,
AIConfiguration.RecognitionEngine.System)
....
in Android 3.0 I am getting a gradle error of "Unresolved reference: SupportedLanguages" for AIConfiguration.SupportedLanguages. AIConfiguration.RecognitionEngine is resolving just fine. Why is this problem happening? What solution/work-around can I implement?
My higher level build.gradle file:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 27
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.1'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
api 'com.android.support:appcompat-v7:27.0.0'
api 'com.android.support:design:27.0.0'
api 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'ai.api:sdk:2.0.7#aar'
compile 'ai.api:libai:1.6.12'
//compile project(':ailib')
application project(':app')
feature project(':chatbot')
}
My module build.gradle file:
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.1'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
implementation project(':base')
//add the google gson library
compile 'com.google.code.gson:gson:2.8.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
One workaround I found that is working is to use ai.api.AIConfiguration.SupportedLanguages which is resolving instead of ai.api.android.AIConfiguration.SupportedLanguages which is not resolving in kotlin in Android Studio 3.0 as mentioned in the question.
However, calling ai.api.android.AIConfiguration.SupportedLanguages works just fine in Java code, in which case it is resolving correctly in Android Studio 3.0. Since ai.api.android.AIConfiguration implements ai.api.AIConfiguration, why this issue is arising is puzzling!
Just use this line instead of previous -
ai.api.AIConfiguration.SupportedLanguages.English,

Categories