Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Use androidx for back compatibility instead of Support Library #71

Closed
victoraldir opened this issue Jan 31, 2019 · 19 comments
Closed

Use androidx for back compatibility instead of Support Library #71

victoraldir opened this issue Jan 31, 2019 · 19 comments

Comments

@victoraldir
Copy link
Contributor

Folks, I experienced a problem when updating cloud_firestore to version 0.9.0

The update requires libraries like androidx.annotation to work.

When I enabled androidx in my project, BarcodeScannerActivity.kt started failing to build because dependencies like

import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat

I migrated the project from Support Library to Androidx and I referencing to this issue for further discussion

@victoraldir victoraldir changed the title Use androidx back compatibility instead of Support Library Use androidx for back compatibility instead of Support Library Jan 31, 2019
@matthewtsmith
Copy link
Contributor

@victoraldir I merged this PR but once I went to use it I'm now having build issues. I'm going to be doing some work next week to figure out what is going on. I'm holding off on publishing this until I can figure that out.

@victoraldir
Copy link
Contributor Author

@matthewtsmith Sorry to hear that. I will check it out and come up with something.

What problem are you facing? Can you paste the stack here?

@manfye
Copy link

manfye commented Feb 10, 2019

yeah same thing happened after i update it to sdk 28.

gradle task 'assembleDebug'...
e: C:\src\flutter.pub-cache\hosted\pub.dartlang.org\barcode_scan-0.0.8\android\src\main\kotlin\com\apptreesoftware\barcodescan\BarcodeScannerActivity.kt: (8, 31): Unresolved reference: ActivityCompat
e: C:\src\flutter.pub-cache\hosted\pub.dartlang.org\barcode_scan-0.0.8\android\src\main\kotlin\com\apptreesoftware\barcodescan\BarcodeScannerActivity.kt: (9, 27): Unresolved reference: content
e: C:\src\flutter.pub-cache\hosted\pub.dartlang.org\barcode_scan-0.0.8\android\src\main\kotlin\com\apptreesoftware\barcodescan\BarcodeScannerActivity.kt: (86, 13): Unresolved reference: ContextCompat
e: C:\src\flutter.pub-cache\hosted\pub.dartlang.org\barcode_scan-0.0.8\android\src\main\kotlin\com\apptreesoftware\barcodescan\BarcodeScannerActivity.kt: (89, 13): Unresolved reference: ActivityCompat

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':barcode_scan:compileDebugKotlin'.

Compilation error. See log for more details

  • 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

@rostopira
Copy link

Master branch works fine, you can push it to pub

@sleith
Copy link

sleith commented Feb 19, 2019

Hi, any update regarding this?
i've been waiting but it's not on pub yet. Please help.
Thanks :)

@manfye
Copy link

manfye commented Feb 19, 2019

@sleith u can try the pull branch for android X support. It work perfectly here

@NatoBoram
Copy link

I needed to add those settings for flutter/flutter#28155 :

android.useAndroidX=true
android.enableJetifier=true

But now it's barcode_scan that's acting up :/

Initializing gradle...                                              0.8s
Resolving dependencies...                                           1.7s
e: /home/natoboram/.pub-cache/hosted/pub.dartlang.org/barcode_scan-0.0.8/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScannerActivity.kt: (8, 31): Unresolved reference: ActivityCompat
e: /home/natoboram/.pub-cache/hosted/pub.dartlang.org/barcode_scan-0.0.8/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScannerActivity.kt: (9, 27): Unresolved reference: content
e: /home/natoboram/.pub-cache/hosted/pub.dartlang.org/barcode_scan-0.0.8/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScannerActivity.kt: (86, 13): Unresolved reference: ContextCompat
e: /home/natoboram/.pub-cache/hosted/pub.dartlang.org/barcode_scan-0.0.8/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScannerActivity.kt: (89, 13): Unresolved reference: ActivityCompat
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':barcode_scan:compileReleaseKotlin'.         
> Compilation error. See log for more details                           
                                                                        
* 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                                                     
Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                      40.1s
Gradle task assembleRelease failed with exit code 1

@marshallchabanga
Copy link

1Go to your dependences and add this just for temporary we are waiting to have a new release
barcode_scan:
git: https://github.com/apptreesoftware/flutter_barcode_reader.git
2 Add this
android.useAndroidX=true
android.enableJetifier=true
3. Update your buildscript with ext.kotlin_version = '1.3.0'
4.Use Gradle com.android.tools.build:gradle:3.3.0

@fritz-playmaker
Copy link

Any idea when they are releasing the fix?

@worldofsites
Copy link

Same issue with API 28 and androidx and barcode_scan.

@kendji
Copy link

kendji commented Feb 28, 2019

I resolved this issue.
import android.support.v4.app.ActivityCompat -> import androidx.core.app.ActivityCompat
import android.support.v4.content.ContextCompat -> import androidx.core.content.ContextCompat
I tried tremendously ways 16 hours.
But here they are.
That's it.

@fritz-playmaker
Copy link

fritz-playmaker commented Feb 28, 2019

Complete changes to make, so as to prevent your app from breaking

1a) Change your Gradle version to 3.2.1

  dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

       ...
    }

1b) Update your gradle to the latest version by changing the distribution URL in "gradle-wrapper.properties"
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

  1. Add AndroidX properties in "gradle.properties" file
	android.useAndroidX=true
	android.enableJetifier=true
  1. Make sure you set the compileSdkVersion in your "android/app/build.gradle" file to 28:
android {
  compileSdkVersion 28

  ...
}
  1. Make sure you replace all the android. dependencies to their AndroidX counterparts (a full list can be found here:. https://developer.android.com/jetpack/androidx/migrate

For example, you could have the following dependencies in your "build.gradle" file

dependencies {
    implementation "com.android.support:support-compat:27.1.1"
    ....
}

You should replace this with:

dependencies {
    implementation 'androidx.core:core:1.0.1'
    ....
}
  1. Change your kotlin version number to the latest version in your build.gradle file
buildscript {
     ext.kotlin_version = '1.3.0'

     .....
     }
  1. Open this file BarcodeScannerActivity.kt in the barcode package folder.
    (This is mine ===>C:\flutter_sdk_stable\flutter.pub-cache\hosted\pub.dartlang.org\barcode_scan-0.0.8\android\src\main\kotlin\com\apptreesoftware\barcodescan\BarcodeScannerActivity.kt)

Make these changes as @kendji suggested
import android.support.v4.app.ActivityCompat ===> import androidx.core.app.ActivityCompat
import android.support.v4.content.ContextCompat ===> import androidx.core.content.ContextCompat

  1. Update your flutter libraries to their latest stable versions. Many of them are now supporting AndroidX. Failure to update them will cause your app not to build, but crash

@matthewtsmith
Copy link
Contributor

Published 1.0 to pub with this fix

@fritz-playmaker
Copy link

@matthewtsmith please update the README.md docs. it still says

dependencies:
  ...
  barcode_scan: ^0.0.3

@fritz-playmaker
Copy link

fritz-playmaker commented Mar 4, 2019

@matthewtsmith . Also does the latest version support AndroidX, if so please add the relevant guidelines to the README.md, if it doesn't please still state it, because it might conflict with other libraries.

@fritz-playmaker
Copy link

Also shouldn't we update to the latest kotlin version 1.3.0?

@riccardo-lomazzi
Copy link

Also shouldn't we update to the latest kotlin version 1.3.0?

I'd also add, in your app/build.gradle file

buildscript {
    ext.kotlin_version = '1.3.20'  // previously was 1.2.51, if you put 1.3.0 it gives warnings about confilicts with 1.3.20, so just put 1.3.0

and

dependencies {
        // 3.2.1 gives "WARNING: Conflict with dependency 'androidx.vectordrawable:vectordrawable'"
        classpath 'com.android.tools.build:gradle:3.3.1' 
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

@mittaus
Copy link

mittaus commented Aug 9, 2019

Using flutter
Flutter 1.7.8+hotfix.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 20e59316b8 (3 weeks ago) • 2019-07-18 20:04:33 -0700
Engine • revision fee001c93f
Tools • Dart 2.4.0

Using barcode_scan: 1.0.0

Add the camera permission to your ./android/app/profile/AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA" />

Add the BarcodeScanner activity to your ./android/app/main/AndroidManifest.xml. Do NOT modify the name.

<activity android:name="com.apptreesoftware.barcodescan.BarcodeScannerActivity"/>

This plugin is written in Kotlin. Therefore, you need to add Kotlin support to your project. See installing the Kotlin plugin.

Edit your project-level ./android/build.gradle file to look like this:

buildscript {
    ext.kotlin_version = '1.3.20'
    ...
    dependencies {
        ...
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Exlude this step

Edit your app-level build.gradle file to look like this:

    apply plugin: 'kotlin-android'
    ...
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
        ...
    }

And work for me.

@BoniWPy
Copy link

BoniWPy commented Nov 19, 2019

1Go to your dependences and add this just for temporary we are waiting to have a new release
barcode_scan:
git: https://github.com/apptreesoftware/flutter_barcode_reader.git
2 Add this
android.useAndroidX=true
android.enableJetifier=true
3. Update your buildscript with ext.kotlin_version = '1.3.0'
4.Use Gradle com.android.tools.build:gradle:3.3.0

THIS IS awesome solution....for me it's WORKS.. thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests