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
Related
Currently, I have completed updating my project to React-Native 0.70.6 (The Latest). Everything is working as expected during development (npm run android) and Apk builds process also generates APK without any error. But when I run my Final APK app suddenly crashes without any error. To detect the reason for crash I have used several debugging tools. Which gives me the error as shown below
java.lang.RuntimeException: Unable to load script.
Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFr assets(CatalystInstanceImpl.java:248)
at com.facebook.react.bridge.JSBundleLoader $1.loadScript(JSBundleLoader.java:29)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundl e(CatalystInstanceImpl.java:277)
at com.facebook.react.ReactInstanceManager.createReactCont ext(ReactInstanceManager.java:1402)
at com.facebook.react.ReactInstanceManager.access $1200(ReactInstanceManager.java:136)
at com.facebook.react.ReactInstanceManager
$5.run(ReactInstanceManager.java:1108) at java.lang.Thread.run(Thread.java:818)
I searched everywhere about this problem on the web. I read several posts and got several suggestions that I have implemented in my files.
My android/build.gradle file :
buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
if (System.properties['os.arch'] == "aarch64") {
ndkVersion = "24.0.8215888"
} else {
ndkVersion = "21.4.7075529"
}
googlePlayServicesAuthVersion = "19.2.0"
firebaseMessagingVersion = "21.1.0"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
classpath 'com.google.gms:google-services:4.3.14'
}
}
allprojects {
repositories {
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
mavenCentral {
content {
excludeGroup "com.facebook.react"
}
}
google()
maven { url 'https://www.jitpack.io' }
}
}
Few configurations of android/app/build.gradle
// other code .....
project.ext.react = [
enableHermes: true,
entryFile: "index.js",
bundleAssetName: "index.android.bundle",
bundleInDebug: true,
bundleInRelease: true
]
def enableSeparateBuildPerCPUArchitecture = true
def enableProguardInReleaseBuilds = true
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
multiDexEnabled true
if (isNewArchitectureEnabled()) {
// We configure the CMake build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
cmake {
arguments "-DPROJECT_BUILD_DIR=$buildDir",
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
"-DANDROID_STL=c++_shared"
}
}
if (!enableSeparateBuildPerCPUArchitecture) {
ndk {
abiFilters (*reactNativeArchitectures())
}
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include (*reactNativeArchitectures())
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// other code ......
}
Detail of java I am using
Openjdk version "18.0.1.1" 2022-04-22
OpenJDK Runtime Environment Homebrew (build 18.0.1.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.1.1+0, mixed mode, sharing)
I have tried creating a fully new project on react native 0.70.6 and generated a signed apk which worked fine but didn't work with dependencies.
I had similar problem. Downgrade gradle helps me in my case.
In: android/gradle/wrapper/gradle-wrapper.properties i changed version from 7.5.1 to 7.3.3.
In: android/build.gradle i changed gradle from : classpath("com.android.tools.build:gradle:7.2.1") to
classpath("com.android.tools.build:gradle:7.1.1")
We are splitting our app into 32 and 64 bit versions as per Google's requirements. As part of this change, we started using the D8 compiler instead of the older DEX compiler. When we use the D8 compiler, our build time has increased from 6 to 20 minutes (we have a large app). We have done extensive research online and the only solution to that we have found to reduce build time is to disable desugaring. However, the app will not build if the desugaring is disabled.
Updating the gradle version to 5.6 from 5.5.1 has not solved our issues when we turn desugaring off. Neither has removing the .gradle and build directories and invalidating + restarting the app. We are using
Android Studio version 3.5.
Build error with android.enableD8.desugaring=false
> Task :app:compileRegionNaDebugAndroidTestJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Exception in thread "main" java.lang.TypeNotPresentException: Type org.gradle.internal.reflect.Instantiator not present
at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85)
at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:54)
at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41)
at java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067)
at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:406)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1623)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)
Caused by: java.lang.ClassNotFoundException: Class org.gradle.internal.reflect.Instantiator not found
at com.google.devtools.build.android.desugar.HeaderClassLoader.findClass(HeaderClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:83)
... 12 more
gradle.properties file
XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.caching=false
android.databinding.enableV2=true
android.enableD8.desugaring=false
build.gradle snippet
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
buildToolsVersion '27.0.3'
testInstrumentationRunner "com.appmps.mobileapp.EspressoTestRunner"
multiDexEnabled true
testApplicationId "com.appmps.mobileapp.test"
}
splits {
abi {
enable true
reset()
if (isEmulatorRun()) {
include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
} else {
include "armeabi-v7a", "arm64-v8a"
}
universalApk false
}
}
useLibrary 'org.apache.http.legacy'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
We would be thankful for suggestions on getting our app to build with desugaring disabled. We are also interested in any additional strategies for reducing build time related to using the D8 compiler.
Thank you!
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'
}
I use:
Windows 7 64 bit,
Android Studio 2.1.2
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode).
My app works fine on my mobile and on Android Emulator.
However when I tried to run debug mode on my Android phone nothing happened.
I made several breakpoints where the program has to stopb but it ignores my breakpoints.
Please help me, if I need to provide additional information let me know.
My build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.example.android.justjava"
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.4.0'
}
I recommend you to try like this:
Select debug Build Flavor.
Set break point at the code always execute.
ex) Activity's onCreate method.
Run as Debug. (Select Menu -> Run -> Debug in AndroidStudio)
Execution will be stopped at the break point.
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.