I have the following POST request that's written by using Java 11's HttpClient. But Android Studio does not recognize the libraries.
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
class Verification {
fun verify(username: String, signature: String) {
try {
HttpClient.newHttpClient().send(HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofString("$username:$signature"))
.uri(URI.create("http://localhost:9080/sse/verify"))
.build(), HttpResponse.BodyHandlers.ofString())
} catch (e: Exception) {
e.printStackTrace()
}
}
}
build.gradle:
android {
compileSdkVersion 29
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "io.example.code"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
And in Android Studio Project Structure the JDK path is set to my default JDK C:\Program Files\Java\jdk-11.0.8 also in modules:
What am i doing wrong? What can i do to implement a Http method with Java 11 HttpClient?
Related
I'm adding a class on the project app for reading external permission ActivityResultCotract.RequestPermission for regiesterActivityResult and not showing in dialogue and intention icon classes and I was trying more times to update the dependencies for Gradle but doesn't still show, and when writing this class showing error can T use an alternative method's the ActivityResultCotract.RequestPermission or add this class manually for my package and this code for Main Activity :
///storagePermissionLauncher = registerForActivityResult(
// new ActivityResultContracts.RequestPermission, granted->(),
// new ActivityResultCallback<ActivityResult> () {
//
// if (granted ) {
// fetch songs
// fetchSongs();
// }
// }
and this Grale for this app :
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 33
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.mp3_playerapp"
minSdkVersion 28
targetSdkVersion 33
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 JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0-alpha04'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.+'
implementation 'androidx.activity:activity:1.6.0-alpha05'
implementation 'androidx.fragment:fragment:1.4.0-alpha05'
implementation 'androidx.activity:activity:1.6.0-alpha04#aar'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha03'
}
I am currently integrating a Unity AR project as a library in a native Android Studio project. It is all fine with the exception that when I try to build/run the project in Android Studio I get the exception from the title:
Could not find :ARPresto:.
Required by:
project :unityLibrary
Search in build.gradle files
I have no idea why this happens since the unity project seems to be successfully integrated as a library and I can open in the in Android Studio project menu.
This is the build.gradle file of the Unity Library:
allprojects {
buildscript {
repositories {
google()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
}
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
apply plugin: 'com.android.library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'ARPresto', ext:'aar')
implementation(name: 'unityandroidpermissions', ext:'aar')
implementation(name: 'VuforiaEngine', ext:'aar')
}
android {
compileSdkVersion 31
buildToolsVersion '30.0.3'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 26
targetSdkVersion 31
ndk { abiFilters 'armeabi-v7a' }
ndk {
// Default ABI list for this app, can be over-ridden by providing an abiList property
// e.g. gradle -PabiList=x86 clean assembleDebug
abiFilters ((project.findProperty('abiList') ?: 'armeabi-v7a, arm64-v8a').split(/,\s*/))
}
versionCode 1
versionName '0.1'
consumerProguardFiles 'proguard-unity.txt'
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
}
}
This is the module and project gradle files of the parent android app:
Project
ext {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
// flatDir {
// dirs "${project(':unityLibrary').projectDir}/libs"
// }
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.project.chemistryar"
minSdk 26
targetSdk 31
versionCode 1
versionName "1.0"
ndk{
abiFilters 'armeabi-v7a','x86'
}
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
}
kotlinOptions {
jvmTarget = '1.8'
}
compileSdkVersion 31
buildToolsVersion '30.0.3'
}
dependencies {
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 project(path: ':unityLibrary')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.android.material:material:1.4.0'
// unity
//implementation project(':unityLibrary')
//implementation fileTree(dir: project(':unityLibrary').getProjectDir().toString() + ('\\libs'), include: ['*.jar'])
//bottom navigation bar
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
I'm trying to start sample_client application of owncloud android library.
You can find the library here :
https://github.com/owncloud/android-library#:~:text=%20ownCloud%20Android%20Library%20%201%20Introduction.%20Using,code%20of%20HEAD...%204%20Compatibility.%20%20More
I changed gradle files to get packages. My problem is as follows:
Execution failed for task ':owncloudComLibrary:generateDebugRFile'.
Could not resolve all files for configuration ':owncloudComLibrary:debugCompileClasspath'.
Could not find com.gitlab.ownclouders:dav4android:oc_support_2.1.5.
Required by:
project :owncloudComLibrary
Could not find com.github.AppDevNext.Logcat:LogcatCore:2.2.2.
Required by:
project :owncloudComLibrary
Simple_client app build.gradle :
apply plugin: 'com.android.application'
buildscript{
repositories{
jcenter()
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies{
classpath 'com.android.tools.build:gradle:4.1.2'
}
}
repositories{
jcenter()
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation project(':owncloudComLibrary')
}
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
// This is pretty ugly but manifest placeholders don't seem to work very well when using different modules
// See https://github.com/openid/AppAuth-Android/issues/325
manifestPlaceholders = [appAuthRedirectScheme: '']
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Library build.gradle :
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
buildscript {
ext {
kotlinVersion = "1.3.31"
}
repositories{
jcenter()
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
api 'com.squareup.okhttp3:okhttp:4.6.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.31"
api 'com.gitlab.ownclouders:dav4android:oc_support_2.1.5'
api 'com.github.AppDevNext.Logcat:LogcatCore:2.2.2'
// Moshi
implementation ("com.squareup.moshi:moshi-kotlin:1.11.0") {
exclude module: "kotlin-reflect"
}
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.11.0"
testImplementation 'junit:junit:4.13.1'
}
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode = 10000900
versionName = "1.0.9"
}
lintOptions {
abortOnError false
ignoreWarnings true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Thank you for your help
I am trying to run an app that I am coding along with in Android Studio 4.1 Development Essentials, Chapter 76. It is an application that uses the Android Room Persistence Library.
The error that I am getting is:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
While being fairly new to Kotlin and Android Studio, I believe the error has something to do with how my build.gradle app file is set up, show below.
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "us.jordanakellogg.roomdemo"
minSdkVersion 26
targetSdkVersion 30
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 "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.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.room:room-runtime:2.2.5'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
kapt "androidx.room:room-compiler:2.2.5"
kapt 'androidx.databinding:databinding-compiler-common:4.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
I will provide my DAO class as well as I feel maybe there might be something wrong with that as well.
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
#Dao
interface ProductDAO {
#Insert
fun insertProduct(product: Product)
#Query("SELECT * FROM products WHERE productName=:name")
fun findProduct(name: String): List<Product>
#Query("DELETE FROM products WHERE productName=:name")
fun deleteProduct(name: String)
#Query("SELECT * FROM products")
fun getAllProducts(): LiveData<List<Product>>
}
Could you help point me in the right direction so I successfully test this app without receiving the "Execution failed for task ':app:kaptDebugKotlin'." error?
I tried to use a new parse sdk from github but after installing android studio throwing below error.
Error:No resource identifier found for attribute 'appComponentFactory' in package 'android'
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: Failed to execute aapt
Attaching the gradle files. Please help if there are any issues to be fixed.
App gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.ashwini.test"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
aaptOptions {
cruncherEnabled = false
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled true
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:27.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.github.parse-community.Parse-SDK-Android:parse:1.23.0'
testCompile 'junit:junit:4.12'
}
Module gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
maven {url 'http://jitpack.io'}
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven {
url 'https://maven.google.com'
}
}
}
ext {
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
}
task clean(type: Delete) {
delete rootProject.buildDir
}