Duplicate R.class after renaming package name for my Android Studio Flutter app - flutter

Tried renaming my Android Studio flutter app package, and it is tunring out as a mess. How can I solve this issue?
Build is failing with the error message:
Execution failed for task ':app:multiDexListDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Error while merging dex archives:
Type com.xxxxx.R is defined multiple times:
....\AndroidStudioProjects\xxxx\build\app\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar: D8: Type com.xxxx.R is defined multiple times: ....\AndroidStudioProjects\xxxx\build\app\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar:com/xxxx/R.class, ....\AndroidStudioProjects\xxxx\build\app\intermediates\javac\debug\classes\com\xxxx\R.class
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

Try to run flutter clean in the terminal first. Or remove /build directory by yourself manually.

On terminal type flutter clean
Restart VSCode
Run flutter get package

this happens because the library you are using uses the same dependences.
SOLUTION 1
in VSCode Search (Ctrl+Shift + P)
in your error com.xxxxx.R. search for keywords from that error.
If there are the same dependences, it means that there are duplicate dependences.
Solution: Delete one of the package you are using.
SOLUTION 2 (Recommended)
in VSCode Search (Ctrl+Shift + P)
in your error com.xxxxx.R. search for keywords from that error.
Find a library that uses the same dependences, then update to the latest package version
4.This solution will keep the library you are using without deleting it

Try flutter clean && flutter get package
And try to use a package https://pub.dev/packages/change_app_package_name
Steps:
dev_dependencies:
change_app_package_name: ^1.0.0
Update dependencies
flutter pub get
Run this command to change the package name.
flutter pub run change_app_package_name:main com.new.package.name
(like flutter pub run change_app_package_name:main com.example.app)

Related

How to solve the error on outdated code when cloning

I am recently want to see and run some other developers code in github and clone it to run in my emulator but it showing some error like this
"Running "flutter pub get" in budgex...
Because budgex depends on basic_utils from path which doesn't exist (could not find package basic_utils at "..\packages\basic-utils-3.3.3"), version solving failed.
pub get failed (66; Because budgex depends on basic_utils from path which doesn't exist (could not find package basic_utils at "..\packages\basic-utils-3.3.3"), version solving failed.)"
i am was trying to install basic_utils package but seem failed how to solve this problem?
Click on the link to get packages in the given environment like VS code, or save your code while pubspec.yaml file is opened – it will get flutter packages for you automatically.
The error says that you are trying to use a library on your local computer: basic_utils; the pub command is searching it in the path ..\packages\basic-utils-3.3.3 but it can't find the library there.
In the pubspec.yaml you should have something like this:
basic_utils:
path: ..\packages\basic-utils-3.3.3
You should be ok replacing this with:
basic_utils: 3.3.3
If the developer has made changes to the library you should ask him the changed library and then update the pubspec with the correct location like described here.

FirebaseAppPlatform.verifyExtends error while running flutter test

When I run my bitbucket pipeline for my project im getting an error during flutter test:
/root/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.24.0/lib/src/firebase_app.dart:18:25: Error: Member not found: 'FirebaseAppPlatform.verifyExtends'.
FirebaseAppPlatform.verifyExtends(_delegate);
^^^^^^^^^^^^^
When I run flutter test in my terminal I don't have these issues.
My pipeline script is:
Build Setup
flutter clean
flutter pub get
flutter pub run build_runner build
bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh)
flutter test
Because there are some breaking change of firebase_core_platform_interface that do not comply with semantic versioning:
https://github.com/firebase/flutterfire/issues/9806
You need to overwrite this library:
Root cause
You are update or installing only a subset of the Firebase plugins (firebase_core, firebase_analytics,...)
Solution
Solution 1: (preferred) Updating to the latest version with flutterfire update check the docs here. But it is not easily because your project will have a lot of packages dependencies to each other like flutter version 2 or 3, so on. Anyway, it is long term solution.
Solution 2: (Fix to run)
You can add to your pubspec.yaml
dependency_overrides:
firebase_core_platform_interface: 4.5.1
Solution 3: (Fix to run)
Update dependencies with this below command line:
flutter pub upgrade --major-versions
Finally, Run the project again by following stuffs:
flutter clean
flutter pub get
cd ios && rm -f Podfile.lock
cd ios && pod install --repo-update
flutter run
That's it!
Run "flutter pub upgrade --major-versions"
run this
flutter pub upgrade --major-versions
than run this
flutter upgrade
I changed my flutter version via flutter channel master. This changed automatically my pubspec.lock.
In my case, restoring previous version of pubspec.lock solved the problem (pug get needed).

Target file "build_runner" not found. - Flutter GraphQL

flutter run build_runner build - return the following result
Target file "build_runner" not found.
This is supposed to generate model classes from schema, but stuck in the above listed issues.
The issue is with the package dependencies. Executing this flutter pub upgrade --major-versions will solve this issue.

How can I fix Flutter_localizations error on the vscode? - Target of URI doesn't exist

I'm trying to use flutter_localizations and I followed this guide
When I save pubspec.yaml on vscode then pub get is ran.
After that vscode can't find app_localizations.dart file.
But this error messages will disappear when I reopen vscode.
Is there anyone with such a problem like me?
Thanks.
Use this command and Open command palette - command + shift + p on the vscode.
Type Dart: Restart Analysis Server and select it.
This error will be gone.
Usually running
flutter gen-l10n
should be enough, however sometimes I'va found myself using
flutter clean && flutter pub get dependencies && flutter packages get
To clean cache, and get the dependencies(which also generate the l10n). 95% of the time the first command should suffice

The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated

I'm running a dart only test in intellij and receiving the following error:
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "pub get" again.
I have tried pub get a number of times. Any ideas? I'm on the dev branch of Flutter (anything using Dart 2.7 pretty much fails with the same or a similar error message).
Edit
I think that if you have a path reference dependency in the pubspec.yaml file it will fail.
Anything like the following fails with the above message if you try to run a dart test in IntelliJ.
dependencies:
test_dependency:
path: ../test_dependency
I'm not suggesting this is a fix for everyone, but it did resolve my particular situation.
Just ran into this error after upgrading flutter from 1.22.6 to 2.0.2 and trying to use build_runner: ^1.12.2 and json_serializable: ^4.1.0 to generate json serialization/deserialization classes & methods.
The problem is apparently related to the pub package when used with relative paths for packages as noted in the following github issues:
https://github.com/dart-lang/pub/issues/2806
https://github.com/dart-lang/pub/pull/2830
One of the commenters in issue 2806 mentioned running flutter create . inside the flutter project folder which rebuilds .dart_tool/package_config.json, adding any missing entries, solving the problem.
No one solved this problem so far?
I've found a staightforward solution and it works fine for me.
You need to close your IDE (VSCode in my case), make sure that is completely closed using process-monitor.
Then open a terminal window manualy in your project folder and run "flutter pub get"
After that just start your IDE normaly and ewerything will work fine.