I've been using ConstraintLayout of version 1.1.2 for a while now. It was working perfectly. Then new MotionLayout came up and I thought why not to try it out. And everything seemed fine.
However I made a mistake of using it in production. Only after some time I noticed some bug reports on ConstraintLayout working not properly. But there are some screens already that depend on MotionLayout, removing which will cause a lot of refactoring.
Is it possible to use MotionLayout(v2.0.0-alpha-05/beta-02) and ConstraintLayout(v1.1.3) for the same project, so that screens that work with MotionLayout would have v2.0.0 and screens that work with ConstraintLayout only would have v1.1.3? Is there some packaging tool to move MotionLayout to a different package? I tried to use shadowJar gradle plugin but failed because MotionLayout is an *.aar dependency not *.jar.
Edit:
I've created a sample where I use jetifier gradle plugin from aosp to rewrite the package names and demonstrate how to use both 1.1.3 and 2.0.0-beta versions in the same project.
You can use jetifier with custom config file to rewrite package name. Just run it on both constraintlayout-2.0.0-beta2.aar and constraintlayout-solver-2.0.0-beta2.jar like this:
./jetifier-standalone -i constraintlayout-2.0.0-beta2.aar -o myconstraintlayout-2.0.0-beta2.aar -c config.json
./jetifier-standalone -i constraintlayout-solver-2.0.0-beta2.jar -o myconstraintlayout-solver-2.0.0-beta2.jar -c config.json
where config.json is the custom config like this:
{
"restrictToPackagePrefixes": [
"androidx/"
],
"reversedRestrictToPackagePrefixes": [],
"rules": [
{
"from": "androidx/(.*)",
"to": "myandroidx/{0}"
},
],
"packageMap": [
{
"from": "androidx/constraintlayout/widget",
"to": "myandroidx/constraintlayout/widget"
}
],
"pomRules": [],
"versions": {
"latestReleased": {}
},
"map": {
"types": {}
},
"proGuardMap": {
"rules": {
"androidx/{any}": [
"myandroidx/{any}"
]
}
},
"stringsMap": {
"types": {}
}
}
You can check the original config file to find out file format.
After that you can use myconstraintlayout-2.0.0-beta2.aar and myconstraintlayout-solver-2.0.0-beta2.jar in your project. Obviously you'll have to change package name for MotionLayout in your project.
It should be possible to automate the process by writing a gradle plugin also.
Edit: it's probably better to repackage constraintlayout-1.1.3, so you can easily update MotionLayout with new versions when they are released.
I faced similar issues - the only possible way to avoid the class collision is to rebuild one of the dependencies with the different package name. It could be done by downloading the code of one of the libraries and recompile it manually on your PC. For example from here.
But I would recommend you to use ConstraintLayout library version 2.0
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta2'
or
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
if you are using AndroidX.
Is contains both ConstraintLayout and MotionLayout so they would not create a conflict in your code. Some small adjustments may be needed in your current code though.
Hope it helps.
Related
I'm new to Kotlin programming language. so... i have downloaded a few extensions such as Kotlin, Kotlin language,Kotlin Formatter, and when i press F5 it gives an ERROR...just one important question which is, should i use another IDE like intellij ?? because i don't really wan't to spend my time on fixing problems, also my computer can't handle android studio so it's between intellij and Vscode.
Error in the link below:
fun main(args: Array<String>) {
println("Hello World!")
}
that's the image of what i tried to debug + ERROR
I also had a hard time with setting up the debugger, and what worked for me was to checkout a template repository from https://github.com/fwcd/kotlin-quick-start and add the following debug configuration (.vscode/launch.json):
{
"version": "0.2.0",
"configurations": [
{
"type": "kotlin",
"request": "launch",
"name": "Kotlin Launch",
"projectRoot": "${workspaceFolder}",
"mainClass": "quick.start.AppKt"
}
]
}
As a bonus, Gradle is set up then, and one can build, run, and test the app out of the box.
Prerequisites
In VS Code I have installed the following plugins:
https://marketplace.visualstudio.com/items?itemName=fwcd.kotlin
https://marketplace.visualstudio.com/itemsitemName=mathiasfrohlich.Kotlin
https://marketplace.visualstudio.com/items?itemName=naco-siren.gradle-language
And I have installed the following packages locally:
snap install openjdk
snap install --classic kotlin
Of course you can debug your Kotlin code in Visual Studio Code. No need for IntelliJ or Android Studio.
To enable debugging in VS Code, you should install the Code Runner extension
https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
and should have the Kotlin command-line compiler installed and configured in your system as well:
https://kotlinlang.org/docs/command-line.html
See the pages below for further, detailed infos:
https://formulahendry.wordpress.com/2017/05/21/code-runner-supports-kotlin-in-visual-studio-code-now/
https://dev.to/mwrpwr/learning-kotlin-programming-with-visual-studio-code-5e29
https://medium.com/#agavatar/programming-with-kotlin-in-visual-studio-code-1d745d6b4ad1
Yes. You can proceed with intellJ. There is first priority i.e. Android Studio but as you mentioned it can not be handled, so you can use IntelliJ.
The advantage of Intelli J it provide by default support files and libraries for Kotlin Development so you don't need to install external extension.
he Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
For more info please visit official website
https://www.jetbrains.com/idea/features/
I usually do following in my projects:
1) define a versions.gradle file, e.g.:
ext {
setup = [
compileSdk: 28,
enableDataBinding: true,
minSdk : 16,
targetSdk : 28
]
androidx = [
supportv4: "1.0.0",
appcompat: "1.0.0",
cardview: "1.0.0",
viewpager: "1.0.0",
material: "1.0.0"
]
}
2) I add this versions file to my projects gradle file:
apply from: './versions.gradle'
3) I use the versions from the file in all my project gradle files for consistant library versions, like e.g.:
implementation "androidx.appcompat:appcompat:${androidx.appcompat}"
Question
How can I handle this gracefully in open source libraries I use? I want that if someone checks out my library and adds the library directly to his projects, that some default version is provided so that this line implementation "androidx.appcompat:appcompat:${androidx.appcompat}" won't throw any error (${androidx.appcompat} should be replaced by 1.0.0 e.g. in this case).
Is there some way to solve this easily? I want that the version file is used if available and a fallback version is used otherwise...
Trying Elvis operator for placing default value can do that trick, so replacing it with operator like below works :
implementation "androidx.appcompat:appcompat:${androidx.appcompat ?: 'default value here'}"
More from here.
Currently I am using Flutter to build my application.
Background
I have followed some guide on building different environments entry files:
https://iirokrankka.com/2018/03/02/separating-build-environments/
which create main_dev.dart and main_prod.dart.
Also I have learnt to build flavor for both iOS and Android:
https://medium.com/#salvatoregiordanoo/flavoring-flutter-392aaa875f36
which now I can use --flavor <FLAVOR> in the command to build different flavor application.
Now I have encountered a problem when I try to combine two skills.
Target Result
Below is what I would like to achieve:
development flavor -> main_dev.dart entry file
production flavor -> main_prod.dart entry file
Problem Encounter
in iOS side, I can target the entry file in .xcconfig file like following:
// ios/Flutter/development.xcconfig
#include "Generated.xcconfig"
FLUTTER_TARGET=lib/main_dev.dart
I know I can add -t lib/main_dev.dart after flutter run command.
However I would like to ask if there is any solution to set
the flutter target file in Android side inside flavor config?
Appreciate for any help.
I would like to ask if there is any solution to set the flutter target
file in Android side inside flavor config?
I don't know the equal of FLUTTER_TARGET for Android flavor. I would to like to learn that too.
But, flutter run -t is not the only option here. When you open a Flutter project (the root project) with Android Studio you will have a default run/debug configuration like below:
When you click Edit Configurations below screen will appear:
There you can set Build flavor and Dart entrypoint. Obviously, you can create multiple configurations for each flavor.
Reference: https://cogitas.net/creating-flavors-of-a-flutter-app/
So, that's a solution for Flutter in Android Studio. For VSCode, I have a workaround. I'm using -t parameter. But I have it automated by VSCode. Under .vscode/launch.json I have configurations like below:
"configurations": [
{
"name": "GoodOne",
"request": "launch",
"type": "dart",
"args": ["--flavor",
"good",
"-t",
"./lib/main-good.dart"
]
},
{
"name": "BadOne",
"request": "launch",
"type": "dart",
"args": ["--flavor",
"bad",
"-t",
"./lib/main-bad.dart"
]
}
]
With this, you can run your flavors by just pressing F5 and choose your config at the upper-left corner.
Again, this is not an exact answer to OP's question, but some workarounds.
While trying to run my project on an android emulator, the device throws this error emulator screenshot. I cannot seem to figure out what I am doing wrong. I am still quite new to react
firstly install babel polyfill
npm install --save #babel/polyfill
then import on top of index.js .
i mean on very top before any import
import "#babel/polyfill";
if got no answer
so
module.exports = {
entry: ["#babel/polyfill", "./app/js"],
};
use it this way on your webpack.config.js
For anyone coming across this post later, #babel/polyfill has been deprecated in favour of core-js. See https://babeljs.io/docs/en/babel-polyfill
If you're using >7.4.0 babel, you should be able to configure this using #babel/env. Set your targets in .babelrc (or whatever you call your babel config)
{
"presets": [
[
"#babel/env",
{
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "67",
"safari": "11.1"
}
}
]
]
}
https://babeljs.io/docs/en/usage#configuration
I'm trying to load a quantized graph into an Android app.
My BUILD file contains
deps = ["//tensorflow/core:android_tensorflow_lib",
"//tensorflow/contrib/quantization:cc_array_ops",
"//tensorflow/contrib/quantization:cc_math_ops",
"//tensorflow/contrib/quantization:cc_nn_ops",
"//tensorflow/contrib/quantization/kernels:quantized_ops"]
The additional quantization deps work for standalone C++ builds.
I can't compile with Bazel, due to a large number of errors in GEMMLOWP. What's the proper way to include gemmlowp and the quantization ops in Android?
Here is an example error:
external/gemmlowp/eight_bit_int_gemm/eight_bit_int_gemm.cc:125:13: error: 'int32_t' is not a member of 'std'
MatrixMap<std::int32_t, ResultOrder> result(c, m, n, ldc);
This is on Ubuntu 16.04 with Bazel 0.3.0.
Here's a gist that has the output of two sequential attempts to build the package - it fails on highwayhash the first time and gemmlowp the second.
https://gist.github.com/ericdanz/81b799f2e0bbb3cc462aa3c90468c71b
Ultimately got it to compile and run with liberal addition of "-std=c++11" in BUILD files for gemmlowp and highwayhash, and substitution of the android framework for the framework dependencies in the quantized ops. It produces fairly different results though, and runs about 4x slower (26-3200ms vs 6-800 ms). I'll try to do a little deeper investigation.
Here's what worked for me - it is basically a combination of all the comments from Eric D above, but I wanted to put it all in one place for someone new who comes across this problem:
Add quantized_ops in deps to libtensorflow_demo.so in the BUILD file for the Android app:
deps = ["//tensorflow/core:android_tensorflow_lib",
"//tensorflow/contrib/quantization/kernels:quantized_ops",]
Modify the deps for quantized_ops in tensorflow/contrib/quantization/kernels/BUILD:
deps = [
"//tensorflow/contrib/quantization:cc_array_ops",
"//tensorflow/contrib/quantization:cc_math_ops",
"//tensorflow/contrib/quantization:cc_nn_ops",
"//tensorflow/core:android_tensorflow_lib",
#"//tensorflow/core",
#"//tensorflow/core:framework",
#"//tensorflow/core:lib",
#"//tensorflow/core/kernels:concat_lib_hdrs",
#"//tensorflow/core/kernels:conv_ops",
#"//tensorflow/core/kernels:ops_util_hdrs",
#"//tensorflow/core/kernels:pooling_ops_hdrs",
#"//tensorflow/core/kernels:eigen_helpers",
#"//tensorflow/core/kernels:ops_util",
#"//tensorflow/core/kernels:pooling_ops",
"//third_party/eigen3",
"#gemmlowp//:eight_bit_int_gemm",
],
Remove/comment out the .Doc() parts in tensorflow/contrib/quantization/ops/array_ops.cc, math_ops.cc and nn_ops.cc
Modify the deps for cc_array_ops, cc_math_ops and cc_nn_ops in tensorflow/contrib/quantization/BUILD:
deps = [
#"//tensorflow/core:framework",
"//tensorflow/core:android_tensorflow_lib",
],
Run bazel build command for Android app with --cxxopt="-std=c++11" flag.