error: attribute 'com.example.b3rk4.myapplication:layout_constraintTop_toTopOf' not found - java

When I open Android Studio my first time, I saw "AAPT2 error: check logs for details" this error.
When I check details wrote:
error: attribute
com.example.b3rk4.myapplication:layout_constraintBottom_toBottomOf'
not found.
error: attribute
'com.example.b3rk4.myapplication:layout_constraintLeft_toLeftOf' not
found.
error: attribute
'com.example.b3rk4.myapplication:layout_constraintRight_toRightOf' not
found.
error: attribute
'com.example.b3rk4.myapplication:layout_constraintTop_toTopOf' not
found.
Java compiler: (1 error) error: failed linking file resources.
What i tried already:
Open with administrator
Build->Clean Project and Build->Rebuild Project
Invalidate Caches / Restart
Add android.enableAapt2=false in gradle.properties (When i do this "AAPT2 error: check logs for details" error transforming to "Process 'command 'C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe'' finished with non-zero exit value 1" and when i look details:
No resource identifier found for attribute
'layout_constraintBottom_toBottomOf' in package
'com.example.b3rk4.myapplication'
No resource identifier found for attribute
'layout_constraintLeft_toLeftOf' in package
'com.example.b3rk4.myapplication'
No resource identifier found for attribute
'layout_constraintRight_toRightOf' in package
'com.example.b3rk4.myapplication'
No resource identifier found for attribute
'layout_constraintTop_toTopOf' in package
'com.example.b3rk4.myapplication'
Java compiler: (3 errors)
Caused by: java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException: Error while executing
process
C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe
with arguments {package -f --no-crunch -I
C:\Users\b3rk4\AppData\Local\Android\Sdk\platforms\android-27\android.jar
-M \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
-S C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\merged\debug
-m -J \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\generated\source\r\debug
-F C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\debug\resources-debug.ap_
--custom-package com.example.b3rk4.myapplication -0 apk --preferred-density 420dpi --output-text-symbols \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\symbols\debug
--no-version-vectors}
Caused by: com.android.ide.common.process.ProcessException: Error
while executing process
C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe
with arguments {package -f --no-crunch -I
C:\Users\b3rk4\AppData\Local\Android\Sdk\platforms\android-27\android.jar
-M \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
-S C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\merged\debug
-m -J \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\generated\source\r\debug
-F C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\debug\resources-debug.ap_
--custom-package com.example.b3rk4.myapplication -0 apk --preferred-density 420dpi --output-text-symbols \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\symbols\debug
--no-version-vectors}
Caused by: org.gradle.process.internal.ExecException: Process 'command
'C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe''
finished with non-zero exit value 1
Changed to classpath 'com.android.tools.build:gradle:3.0.0'
Changed to buildToolsVersion "27.0.2"
I installed Java jdk, Android Studio, Sdk thinks very carefully.
Added path C:\Users\b3rk4\AppData\Local\Android\Sdk\platform-tools and C:\Users\b3rk4\AppData\Local\Android\Sdk
I unistaled everythink and installed again be carefully and noting changed...
Can you help me please? I were using Android Studio normally 1 month ago and I format my computer and then I can't use any more
My 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.0.0'
// 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
}
My build.gradle (Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.example.b3rk4.myapplication"
minSdkVersion 15
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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'
}

Related

Execution failed for task :app:compileFlutterBuildDebug

Hi i don`t know what to do with this problem every time when i want to run my project
this Error:
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
Could not write file to C:\Users\elkha\OneDrive\Документы\crypto_list2\build\app\intermediates\flutter\debug\flutter_assets\shaders/ink_sparkle.frag.spirv
Target debug_android_application failed: ShaderCompilerException: Shader compilation of "C:\Users\elkha\flutter\packages\flutter\lib\src\material\shaders\ink_sparkle.frag" to "C:\Users\elkha\OneDrive\Документы\crypto_list2\build\app\intermediates\flutter\debug\flutter_assets\shaders/ink_sparkle.frag" failed with exit code 1.
impellerc stdout:
impellerc stderr:
Could not write file to C:\Users\elkha\OneDrive\Документы\crypto_list2\build\app\intermediates\flutter\debug\flutter_assets\shaders/ink_sparkle.frag.spirv
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\elkha\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1151
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\elkha\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 49s
Exception: Gradle task assembleDebug failed with exit code 1
My build.gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.elcode.crypto_list2"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
My build.gradle2:
buildscript {
ext.kotlin_version = '1.5.30'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
settings.gradle:
include ':app'
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
gradle.properties:
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.overridePathCheck=true
I run it in Andtoid Studio but in VS it gives me this two error it says that i need to update my jdk in gradle from 1.8 to 11 i search solution for this problem but i don`t found anything , i try to channge it in android studio Project Settings but in gradle settings there is not Gradle project stettings to change jdk, i try to change from build.gradle but it is not work.In stackoverflow i found one solution it say that i need to change my gradle version to older but it not work too.I use emulator and when i run it on chrome it works.Please help.
Faced same exact error impellerc stdout:... when building my sample flutter on my mac laptop.
I was able to resolve this error using the following steps below :
On your Mac, choose Apple menu > System Settings.
Scroll and click Privacy & security, then scroll down to security section.
Click the lock icon to unlock it,
then enter an administrator name and password. Select the sources
from which you’ll allow software to be installed: There should be a
button that says "Allow anyway" which when clicked will prompt for administrator name and password. If not make sure you've cancelled
the error dialog.
Dev Environment:
------------------------------------------------------------
Flutter 3.7.1
Gradle 7.6
Kotlin: 1.7.10
Groovy: 3.0.13
JVM: 17.0.6 (Homebrew 17.0.6+0)
OS: Mac OS X 13.0 aarch64

Could not resolve all artifacts for configuration ':classpath'. > Could not resolve com.android.tools.build:gradle:4.1.0

This error came up out of nowhere, until then everything worked fine for months.
Now even creating a new project results the same error without any modification.
flutter run ->
Using hardware rendering with device sdk gphone x86 arm. If you notice graphics artifacts, consider enabling software
rendering with "--enable-software-rendering".
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:4.1.0.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:4.1.0.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 4.8s
Exception: Gradle task assembleDebug failed with exit code 1
app level build.gradle ->
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.utilapp"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
project level build.gradle ->
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
flutter doctor ->
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.1, on macOS 11.1 20C69 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[!] Xcode - develop for iOS and macOS
! CocoaPods 1.7.5 out of date (1.10.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on
the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.54.1)
[✓] Connected device (2 available)
! Doctor found issues in 1 category.
Check your internet connection. This error appeared for me when the connection suddenly went down.

compileOptions set to JavaVersion 1.8 cause gradle to fail sync

I would like to use some java 8 features in my app (namely the usage of a json library)
However, when I add
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
to my build.gradle the Gradle project sync failes:
A problem occurred configuring project ':app'.
java.lang.NullPointerException (no error message)
I am using Android studio on Ubuntu 19.04 with the following Java versions installed
wouter#Wouter-Laptop:~/Android/Sdk$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in auto mode
wouter#Wouter-Laptop:~/Android/Sdk$ sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/javac to provide /usr/bin/javac (java
My build.gradle looks like
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "nl.wouter.cycleweatherapp"
minSdkVersion 21
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'org.osmdroid:osmdroid-android:6.1.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.material:material:1.0.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
Removing the Java 1.8 part in the build.gradle file removes the error but gives no java 1.8 features.
Next to switching and installing java versions I have tried to invalidate and regenerate the gradle cache.
I have no clue how to proceed, can anybody help me?
I finally fixed it by installing a Ubuntu LTS in vitrualbox and using that to do the development

Azure Pipeline Gradle build fails for Spring

Im trying to build and deploy a Spring API on Azure via a Yaml pipeline. But i get an error during the spring application gradle build saying.
Error: /home/vsts/work/1/s/gradlew failed with return code: 1
Could not find org.springframework.boot:spring-data-rest-hal-browser:
Expanding the Error,
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.springframework.boot:spring-data-rest-hal-browser:.
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 39s
1 actionable task: 1 executed
Error: /home/vsts/work/1/s/gradlew failed with return code: 1
at ChildProcess.<anonymous> (/home/vsts/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/2.151.0/node_modules/vsts-task-lib/toolrunner.js:639:25)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
##[error]Error: /home/vsts/work/1/s/gradlew failed with return code: 1
##[section]Finishing: Gradle
Things i have tried.
I have tried changing specifying the versions of spring-data-rest-hal-browser in my project from.
compile("org.springframework.boot:spring-data-rest-hal-browser")
to
compile("org.springframework.boot:spring-data-rest-hal-browser:2.4.0.RELEASE")
and finally
compile("org.springframework.boot:spring-data-rest-hal-browser:3.0.8.RELEASE")
But still the same Error results
This is my current build.gradle file in my repo
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.test.spring.api'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.11'
repositories {
mavenCentral()
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-data-rest-hal-browser")
compile("org.springframework.data:spring-data-rest-webmvc:3.1.5.RELEASE")
}
And this is my current azure-pipelines.yml file
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/java
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
steps:
- task: Gradle#2
inputs:
workingDirectory: '$(system.defaultWorkingDirectory)'
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
- task: CopyFiles#2
displayName: 'Copy Files to: Wireframe Directory on development server'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- script:
cd '$(Build.ArtifactStagingDirectory)';
ls
- task: FtpUpload#1
displayName: 'FTP Upload: $(Build.ArtifactStagingDirectory)'
inputs:
credentialsOption: inputs
serverUrl: '[test server url]'
username: '[test username] '
password: '[test password] '
rootDirectory: '$(Build.ArtifactStagingDirectory)'
remoteDirectory: D:\home\site\wwwroot\webapps\ROOT\
preservePaths: true
I want to be able to automatically deploy my spring application to the server URL by pushing my code to it via the Azure devops pipeline which would build and deploy the spring application.
Thanks
So i resolved the issue by making some changes to the build.gradle file and build pipeline using help from the Microsoft Azure Repository for Intellij on Github: see here
My new build.gradle file looks like this:
plugins {
id 'org.jetbrains.intellij' version '0.4.1' apply false
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
/**
*This is task for update Gradle wrapper version.
*/
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
distributionUrl = "https://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
apply plugin: 'io.spring.dependency-management'
group = 'com.test.spring.api'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
allprojects {
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
}
task unitTest(type: Test) {
exclude '**/ApplicationTests/**'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'org.springframework.data', name: 'spring-data-rest-hal-browser', version: '3.0.8.RELEASE'
compile("org.springframework.data:spring-data-rest-webmvc:3.1.5.RELEASE")
}
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
tasks.withType(FindBugs) {
ignoreFailures = true
reports {
html { enabled = true }
xml.enabled = !html.enabled
}
}
/**
* Preparing for release build
*/
task prepRelease() {
}
Also modified the azure-pipelines.yml file to include stacktrace and info to assist in debugging other gradle and build errors.
tasks: 'build --stacktrace --info'

android JDBC mysql java connector app:preDexDebug

I'm trying to learn how to use the JDBC to connect a application to a MySQL database.
I'm using the Android Studio.
I downloaded "mysql-connector-java-5.1.37" from the MySQL website.
Just for put the "mysql-connector-java-5.1.37-bin.jar" in libs folder of a Hello World application and compile I receive :
Error:Execution failed for task ':app:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1
the build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "br.com.myaplication.helloworld"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
}
Try to sync your project
Tools -> Android -> Sync Project with Gradle Files
And then rebuild your project:
build -> rebuild project
I had the same issue and the problem was in the mysql-connector-java-5.1.37.jar file. I downloaded an older version (mysql-connector-java-3.0.17-ga-bin.jar) from here and worked like a charm.
To get the connection use:
Class.forName("com.mysql.jdbc.Driver").newInstance();
String connection = "jdbc:mysql://"+ your_ip + ":"+ your_port +"/"+ database_name;
conn = DriverManager.getConnection(connection, user, pass);
Just in case, don't forget to compile it in your build.gradle:
dependencies {
//other stuff
compile files('libs/mysql-connector-java-3.0.17-ga-bin.jar')
}
PD: This only works if you use the connection from and AsyncTask
Because Distributed mysql-connector-java-5.1.37-bin.jar is compiled for Java1.8, current Android dex compiler cannot recognize it.
$ javap -v com/mysql/jdbc/JDBC42Helper.class| grep "major version"
major version: 52
On the oher hand, mysql-connector-java-5.1.36.jar is compiled for Java1.6.
$ javap -v com/mysql/jdbc/JDBC4Connection.class |grep "major version"
major version: 50
5.1.37 supports JDBC4.2, so requires Java1.8.

Categories