Will apps developed using chaquopy create issues while deployment? - android-studio

I would like to use chaquopy for the communication between java/kotlin and python code in android Studio. Below shown is my build gradle file:
plugins {
id 'com.android.application'
id 'com.chaquo.python'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.image_processing_using_chaquopy"
python{
pip{
install "numpy"
install "opencv-contrib-python-headless"
install "pillow"
}
}
sourceSets{
main{
python{
srcDirs = ["src/main/python"]
}
}
}
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "x86"
}
python{
buildPython "C:/Users/hp/AppData/Local/Programs/Python/Python39/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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Here, we are giving the python.exe local path and chaquopy is not listed in the dependencies too. Will it cause any problem while deploying this app on android phones or some other external devices?

Here, we are giving the python.exe local path
This only affects the build process: this path is not used at runtime. In fact, it couldn't be used at runtime even if we wanted to, because an Android app has no direct access to the filesystem of your computer, even when you're using an emulator.
However, to make it easier for other developers to build your source code, it would be better to remove the buildPython line and allow Chaquopy to find Python on the PATH, as it says in the documentation. If you installed Python from python.org using the default settings, then the py launcher will already be on the PATH, so this will work automatically.
chaquopy is not listed in the dependencies too
That's no problem: the Chaquopy plugin at the top of the file will add any necessary dependencies.

Related

Cannot access 'kotlinx.coroutines.CoroutineScope' which is a supertype of 'androidx.lifecycle.LifecycleCoroutineScope'

Tried to use room api and had to deal with asynchronous tasks you know why.
I chose kotlin coroutines and androidx.lifecycle. Tried to write some code and got 2 errors displaying in IDE
Cannot access 'kotlinx.coroutines.CoroutineScope' which is a supertype of 'androidx.lifecycle.LifecycleCoroutineScope'. Check your module classpath for missing or conflicting dependencies
Cannot access class 'kotlinx.coroutines.Job'. Check your module classpath for missing or conflicting dependencies
error
Here is my gradle module
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.jacksafblaze.sqlitedemo"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures{
viewBinding true
}
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 "androidx.room:room-ktx:2.3.0"
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
implementation'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
implementation'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:5'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
and gradle project
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I tried to invalidate caches and restart, to recreate app from scratch, and to reinstall android studio and I am still getting this error.
upgraded 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' to
'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-RC' and everything works fine
I have the same problem, if I manually add imports in the class the project will compile but the IDE will still display an error.
If you don't want to wait coroutines-android 1.6 release manually adding the import is a workaround, but you will have no autocompletion.
Android Studio build without autocompletion example
You could also have some problems with room, moshi and all libraries that use kapt, you can try to update to latest release (beta/RC) to see if the problem will be fixed in new releases.
For example, when I am writing this lines, moshi is not compatible with kotlin 1.6 yet, and a fix is planed to be released as soon as possible, see here for details.

Build error when trying to Run basic activity

I'm on day 1 of learning Android Studio / Kotlin and working my way through the (official?) tutorials.
Having added some basic views to an empty layout and resolved a couple of "coding practice" warnings, when I try to run the app on a USB connected tablet, I get a build failed message.
(I haven't got as far as any Kotlin coding yet.)
I'm completely out of my depth at this stage and can't find a solution that isn't beyond my level of understanding.
The errors are ...
Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
Caused by: java.lang.ClassNotFoundException: kotlin.reflect.full.KClasses
If there's any other information worth sharing, I'm afraid I don't know what it is at the moment.
ANy suggestions on what I need to do to or investigate to resolve the build fail?
First build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Second build.gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.test04"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Try these steps.
Update your Kotlin version from "1.5.10" to the latest "1.5.31" in your first build.gradle file. Also update the Kotlin plugin: File -> Settings -> Languages and Frameworks -> Kotlin and if there's a new version there will be an Install button to click. Then restart Android Studio and run your project to see if it will work.
If that doesn't work, you can manually add the missing reflection library to your project. I don't see in your dependencies anything that uses reflection, but maybe I'm missing something. So, add this line into the dependencies section of your second build.gradle file:
implementation "org.jetbrains.kotlin:kotlin-reflect"
Then click the "Sync Project with Gradle Files" button near the right end of the toolbar (elephant with blue arrow icon), and try running your project again.
The Android Build Tools you're using is also out of date. I'm not sure it could be related, but you can update that as well in the first build.gradle file. Change the 4.2.2 to 7.0.3 and click the Gradle sync button again. Android Studio might complain that you need to update your Gradle version, so click yes if it offers to update it for you.

shadow jar to avoid dependency duplication in android studio

I am building an android application in android studio but am having trouble with duplicate dependencies.
Duplicate class javax.inject.Inject found in modules jetified-javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-javax.inject-2.5.0-b42.jar (org.glassfish.hk2.external:javax.inject:2.5.0-b42)
Both these dependencies were quite useful to me and i tried excluding the offending part of the dependencies from either of them which just ended up breaking one or the other.
I have been reading about shadow jars which from what i heard of sounded like a magic bullet so i tried it. From what i had read and heard you just added it as a dependency and it magically fixed everything. I tried adding it and i was still getting the error but i read online it is necessary to have the java or groovy plugin if you want it to work with out a lot of work. Either of these makes android studio very unhappy as android has its own slightly modified java or something.
Advice on how to get the shadow jar working would be much appreciated, but also if anyone has any other work arounds that would let me keep using the two clashing dependencies i would love to hear. I sorry if i made some newbie mistakes.
My gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.scrood"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
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 'com.github.jengelman.gradle.plugins:shadow:6.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.picasso:picasso:2.5.1'
implementation 'org.glassfish.jersey.core:jersey-client:2.27'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.27'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.10.4'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.4'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation ('com.google.android.libraries.places:places:2.3.0')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Library not installed with build make Android Studio but works with CMAKE-GUI

System information:
Android Studio 3.2.1
Linux Ubuntu 16.04
Introduction
I recently came across a problem with my IDE (Android Studio). I use it to develop a Native / Java Application alongside Gradle and CMakeLists.
I use a few CMakeLists to export some functions in C/C++ to use with my app.
So these Cmakelists will create some library that can be used.
Problem
When I "make" my project it will build successfully, but the library doesn't change, whether it's modified, or not.
After that, I thought that I might need to "Clean my project" before doing it, but nothing good happened.
You can see my build.gradle under the post.
Tried Solution
The workaround I found is to compile each library with CMAKE-GUI and then compile my Android project to see the modification previously made.
That's bad and not normal, I think.
Help
I want to know why my project doesn't make again my library and "install" it in the appropriate folder.
It's unnecessary to show my CMakeLists because it works on CLion with Linux and Windows with Visual Studio.
Build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.media.[NAME_OF_MY_PROJET]"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk { abiFilters "armeabi-v7a" }
externalNativeBuild {
cmake {
cppFlags "-O3 -fno-stack-protector -fintegrated-as "
arguments "-DANDROID_ABI=armeabi-v7a", "-DANDROID_TOOLCHAIN=clang",
"-DANDROID_NATIVE_API_LEVEL=24", "-DANDROID_NDK=/Android/Sdk/ndk-bundle",
"-DANDROID_STL=c++_static", "-DANDROID_SDK_ROOT=/Android/Sdk/"
}
}
}
buildTypes {
/* customDebugType {
debuggable true
} */
debug {
jniDebuggable true
}
/* release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}*/
}
externalNativeBuild {
cmake {
path "../CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
}

can't get gradle to accept java-client-6.0.0-BETA1.jar in android studio 3

I'm new to android studio. I'm trying to get Android Studio Gradle to build with appium's java-client-6.0.0-BETA1.jar. I'm implementing appium. I believe android studio is install right. I've downloaded the recommended files for appium, selenium-server-standalone-3.8.1.jar, selenium-remote-driver.jar, selenium-java-3.8.1.zip and anything else I can see needed. Appium server is installed and working. An android emulator is running and working.
I get this error:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Repositories\ApkProjects\EndToEndAndroidTest\app\libs\java-client-6.0.0-BETA1.jar
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:550)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.lambda$convertToDexArchive$1(DexArchiveBuilderTransform.java:488)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing io/appium/java_client/touch/TapOptions.class
The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
I've tried the recommended fix - makes no difference. I've updated guava-23.3-android also which was giving similar errors.
The gradle.build file is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.nwri.endtoendandroidtest"
minSdkVersion 18
targetSdkVersion 26
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'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
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'
// compile 'com.google.guava:guava:23.3-android'
}
I've searched the web and can't find anyone having this issue. Here is a screen shot if that helps:
Android studio
Setting Source Compatibility and Target Compatibility to 1.8 in Project Structure dialog helped me.
While manual adding
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
did not help.

Resources