I am using Android Studio version
Android Studio 3.2 Canary 14
Build #AI-181.4668.68.32.4763614, built on May 4, 2018
JRE: 1.8.0_152-release-1136-b02 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6
While investigating the new Architectural navigation components android.arch.navigation I have encountered this build failure.
AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver$1","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...
...
Program type already present: android.support.v4.os.ResultReceiver$1
My app gradle build resembles:-
apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"
android {
compileSdkVersion 'android-P'
defaultConfig {
applicationId "com.research.frager"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
def nav_version = "1.0.0-alpha01"
implementation "android.arch.navigation:navigation-fragment:$nav_version"
implementation "android.arch.navigation:navigation-ui:$nav_version"
// optional - Test helpers
androidTestImplementation "android.arch.navigation:navigation-testing:$nav_version"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha2'
}
and project level gradle build:-
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha01"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried refactoring to AndroidX, however I get a message stating No usages found in project, so why is this "v4" class still being mentioned?
I've been looking at this issue and I have sorted the main issue here by excluding the support package when adding the dependency to the library, doing this:
implementation("android.arch.navigation:navigation-fragment:$nav_version") {
exclude group: 'com.android.support'
}
That would allow you to run the application. However, this artifact is using the support artifacts rather than the androidx artifacts. Looking at the documentation, we can see that NavHostFragment is extending support.v4.Fragment
https://developer.android.com/reference/androidx/navigation/fragment/NavHostFragment
So, in short, you are presented with three options, as far as I can see. The first one is to drop the androidx artifacts and use the support ones which eventually depends on how big your app is.
The second option is to drop the navigation library and go back to the classic way of dealing with navigation which, I guess, is probably undesirable for you.
The third option is to implement a navigation host of your own which I don't know how much work it would be.
This response will remain accurate until Google releases the androidx version of the library which I am surprised they haven't already.
Hope that was helpful.
Related
I'm new to java and its build scripts. I've already got a spring boot messaging service with stomp and sockjs. I want to send and receive messages from an android app. I'd like to use https://github.com/NaikSoftware/StompProtocolAndroid for the stomp client. I have problems setting it up, though.
I followed the steps described on that side, but it's kinda outdated. The server example linked there https://github.com/NaikSoftware/stomp-protocol-example-server has one build.gradle file and on my android studio there are two files, so I'm kinda confused where to put them properties.
I have cleaned android studio project with default build.gradle files. They look like this:
first file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
second file:
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.chatapp"
minSdk 21
targetSdk 32
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.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.android.volley:volley:1.2.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
and I added maven { url "https://jitpack.io" } to the first file right under mavenCentral()
and implementation 'com.github.NaikSoftware:StompProtocolAndroid:{latest version}' to the second file in the dependencies scope.
It syncs properly with a warning: Failed to resolve: com.githubAffected Modules: app
but when I build I get whole bunch of errors:
I tried to open them links but it returns "error 404" which means that these websites don't exist.
I also googled this error: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
I found some "fixes", but they don't work for me, probably they're also outdated.
How can I add this library to my android app?
I've found out that I have to put maven { url 'https://jitpack.io' } inside a settings.gradle file, not the top-level build one and it works now.
I'm in the process of converting my android app from using simple file IO to using a proper database, so I've been going through the tutorials for Android Jetpack's Room. I'm having problems trying to specify the room.schemaLocation argument. My build.gradle file looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 31
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.austinweaver.myapp"
minSdkVersion 16
targetSdkVersion 31
multiDexEnabled true
versionCode 13
versionName "2.4.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
* javaCompileOptions {
* annotationProcessorOptions {
* arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
* }
* }
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.gms:play-services-auth:20.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.android.gms:play-services-ads:20.5.0'
implementation 'com.android.support:multidex:1.0.3'
implementation ('io.socket:socket.io-client:2.0.0') {
exclude group: 'org.json', module: 'json'
}
implementation "androidx.room:room-runtime:2.4.0"
annotationProcessor "androidx.room:room-compiler:2.4.0"
androidTestImplementation "androidx.room:room-testing:2.4.0"
}
The block marked with the *s is the issue: without it, my app runs fine but tells me to specify the room.schemaLocation. With that block, the gradle sync works but then the app build fails with the following message:
Unable to find method 'java.nio.file.Path.of(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;'
java.nio.file.Path.of(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I've tried restarting Android Studio and tried some scattered solutions I found by trying to google the error message, but all the relevant things I found were deprecated or didn't work.
Let me know if there's any information I should have included here, because I'm not sure what else in my project even relates to this. Thanks for any help!
Edit: my project-level build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have been wanting to work on getting Akka Streams (java) to work with Android Studio for a learning project. I add the Akka Actor and Akka Streams dependency to the build.gradle and it syncs perfectly well, adding both of those to the external files. The project bulids fine, but once deployed the app crashes with the following error
Failed to open dex files from /data/app/com.example.akkamagic-ln3G_VACZwI9pFOWqDOdPQ==/base.apk because: Failure to verify dex file '/data/app/com.example.akkamagic-ln3G_VACZwI9pFOWqDOdPQ==/base.apk': Bad index for method_handle_item method_idx: ffff >= f99b
I've come across things that told me to insure that
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
That's added. I've set jetifier to false, since that created a different set of errors and I've added the following for file conflicts.
packagingOptions {
pickFirst 'google/protobuf/*'
pickFirst 'google/protobuf/compiler/plugin.proto'
pickFirst 'reference.conf'
}
Here's the entire build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.akkamagic"
minSdkVersion 27
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
packagingOptions {
pickFirst 'google/protobuf/*'
pickFirst 'google/protobuf/compiler/plugin.proto'
pickFirst 'reference.conf'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
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'
implementation 'io.magicthegathering:javasdk:0.0.16'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.typesafe.akka:akka-actor_2.12:2.6.3'
implementation 'com.typesafe.akka:akka-stream_2.12:2.6.3'
}
and the gradle.properties
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=false
At this point I don't have any actual code in the project that uses the akka library. If I remove the two akka dependencies from the build.gradle the project syncs, builds, deploys and runs as it should.
I am aware that Akka Streams probably isn't the best for the app I'm running, but I'm just trying to really learn how akka streams works and I don't want to have to learn HTML/CSS/JavaScript right now.
I am trying to add firebase in my project but when I implement 'com.google.firebase:firebase-messaging:19.0.0' and 'com.google.firebase:firebase-core:17.0.0'.
build.gradle(here is the error)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.user.mikripoli"
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "2g"
}
}
dependencies {
implementation 'com.roughike:bottom-bar:2.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.flaviofaria:kenburnsview:1.0.7'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation 'com.google.firebase:firebase-messaging:19.0.0'
implementation 'com.google.firebase:firebase-core:17.0.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'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.0.0'
implementation 'com.github.ahmedshaban1:EasySlider:1.0.0'
implementation 'com.liangfeizc:SlidePageIndicator:1.1.0#aar'
implementation 'me.relex:circleindicator:1.2.2#aar'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}
the other gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()
maven {
url "https://maven.google.com"
}
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The error that show about com.android.support:support-v4:28.0.0:
Dependencies using groupId com.android.support and androidx.* can not
be combined but found
IdeMavenCoordinates{myGroupId='com.android.support',
myArtifactId='cardview-v7', myVersion='28.0.0', myPacking='aar',
myClassifier='null'} and
IdeMavenCoordinates{myGroupId='androidx.coordinatorlayout',
myArtifactId='coordinatorlayout', myVersion='1.0.0', myPacking='aar',
myClassifier='null'} incompatible dependencies
Inspection info:There are some combinations of libraries, or tools and
libraries, that are incompatible, or can lead to bugs. One such
incompatibility is compiling with a version of the Android support
libraries that is not the latest version (or in particular, a version
lower than your targetSdkVersion).
Also when I build the apk it shows this error:
Manifest merger failed : Attribute application#appComponentFactory
value=(android.support.v4.app.CoreComponentFactory) from
[com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91 is also present at
[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86
value=(androidx.core.app.CoreComponentFactory). Suggestion: add
'tools:replace="android:appComponentFactory"' to element
at AndroidManifest.xml:13:5-354:19 to override.
adding tools:replace="android:appComponentFactory" doesn't work though
With new release, libraries are migrated from the Android Support Libraries to the Jetpack (AndroidX) Libraries.
The updated libraries will not work unless you make the following changes in your app:
Upgrade com.android.tools.build:gradle to v3.2.1 or later.
Upgrade compileSdkVersion to 28 or later.
Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.
Method-1 :
add this two in your gradle.properties File, without updating anything
android.useAndroidX=true
android.enableJetifier=true
Method-2
if Method-1 doesn't solve your problem
do one thing
if you are using android studio version 3.2 or higher
go to Refactor>Migrate to AndroidX...
According to the firebase site to solve this issue:
Update your app to use Jetpack (AndroidX), you can do this by adding these two lines: android.useAndroidX=true and android.enableJetifier=true into file gradle.properties in the project root directory. Or you can do another method
Upgrade com.android.tools.build:gradle to v3.2.1 or later (in project build.gradle file)
Upgrade compileSdkVersion to 28 or later (in project build.gradle file)
Either downgrade those Firebase dependencies - or migrate to androidx.
The Jetifier is rather useless, because having control over the own dependencies.
You are using both support libraries and androidx libraries and you can't do it.
Cloud Messaging version 19.0.0 is in the June release. Check the official release notes of Firebase Libraries:
This release is a MAJOR version update and includes breaking changes.
With this release, libraries are migrated from the Android Support Libraries to the Jetpack (AndroidX) Libraries.
The updated libraries will not work unless you make the following changes in your app:
Upgrade com.android.tools.build:gradle to v3.2.1 or later.
Upgrade compileSdkVersion to 28 or later.
Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.
28.0.0 was the last version of the original support libraries and these are no longer maintained. All functionality which was present in the support libraries is now a part of the AndroidX namespace and Google recommends that you move to AndroidX.
In Android Studio 3.2 and higher you can migrate by doing a Refactor->Migrate to AndroidX
However note that there may be some changes that you may have to do manually if you've specialized your configuration.
Here's a video on the topic and the official documentation
Try this and sync your project, if this can help you
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
UPD. I have read these question and answer (Class file for com.google.android.gms.internal.zzaja not found). But I doesnt understand what strings i need to add or remove in my project.
Because I havent this and other strings in my code:
compile 'com.google.android.gms:play-services-location:9.2.0'
I develop an android app with use of FireBase. And when I want to build my project I have an error:
Error:(39, 25) error: cannot access zzanb
class file for com.google.android.gms.internal.zzanb not found
The error was caused by invoking statement: FirebaseAuth.getInstance().getCurrentUser();
Projects build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Modules build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "xxx.yyy.zzz"
minSdkVersion 19
targetSdkVersion 25
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(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.firebase:firebase-core:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.1.0'
compile 'com.firebaseui:firebase-ui:0.6.0'
compile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
apply plugin: 'com.google.gms.google-services'
Please, help me to solve that error)
P.S I have already read that question (Firebase Error cannot access zzanb after using play-services-xxx:9.8.00), but i didnt understand anything, what i need to add or remove from my build.gradle files in my situation.
You're mixing libraries from old and new Firebase released. Everything from Firebase that you use should be in parity. This line is reference an library from a very old Firebase release (before it became the Firebase platform at Google):
compile 'com.firebaseui:firebase-ui:0.6.0'
If you want to use the Firebase-UI library, you should use the new version of it that matches the version of the main client library you're using. You're using 10.0.1, so according to the table on the Firebase-UI github I just linked, you want this dependency:
compile 'com.firebaseui:firebase-ui:1.1.1'
Always make sure your Firebase-UI library matches the core Firebase SDK you're using.
It looks like in your case Doug's fix resolved your issue, but we recently encountered the same problem with a different root cause.
In our case, we had configured our IDE project to use JDK8 but failed to check which version of the JDK was in use in the terminal. Because React Native runs Gradle from the command line when you type 'react-native run-android' Gradle was attempting to build using JDK10 which caused obvious issues since Android currently only supports up to JDK8. Once we configured the terminal to use JDK8 the issue was resolved.
TL;DR: Check what version of the JDK you are using in the terminal.
Getting following error:
error: cannot access zza
class file for com.google.android.gms.common.internal.safeparcel.zza not found
dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-analytics:17.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.android.support:support-v4:28.0.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.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
/* implementation 'com.google.firebase:firebase-core:9.2.0' // this line must be included to integrate with Firebase
implementation 'com.google.firebase:firebase-messaging:10.2.1' // this line must be included to use FCM*/
//implementation 'com.google.android.gms:play-services:10.2.1'
implementation 'com.google.android.gms:play-services-maps:10.2.1'
implementation 'com.google.firebase:firebase-core:10.2.1'
implementation 'com.google.firebase:firebase-messaging:10.2.1'
}