Unable to migrate Flutter project to AndroidX - android-studio

I have a Flutter project in Android Studio. I am planning to migrate to AndroidX. Whenever I do Refactor -> Migrate to AndroidX, Android Studio shows error message:
You need to have compileSdk set to at least 28 in your module build.gradle to migrate to AndroidX.
However I have already set the compileSdkVersion 28 in my app/gradle.build file.
Is there anything else I need to do?

I was able to resolve my issue:
Open the Flutter project into Android Studio
Right click on the android directory, click on Flutter -> Open Android module in Android Studio. It asked me to upgrade my gradle plugin.
Then I installed Google Play Services. Tools -> SDK Manager -> SDK Tools and check the Google Play Services.
After the Google Play Services Installed, I did Refactor -> Migrate to AndroidX.
It started working.
Note: Do the refactor from the project window you opened in the step 2.

Here is how I got rid of "compileSdkVersion 28" error. But before I solved it this way, I upgraded Android Studio IDE from 3.4.1 -> 3.5.1. I am not sure if this was really needed. So whatever version of IDE you have, see if you can use following steps to solve it.
Go to "Project Structure" - (2nd icon on left of AVD Manager icon on top right corner of IDE)
On "Project Structure" dialog under left navigation click on Project Settings->Modules
After selecting Modules, on the right pane you should see 3 tabs Sources, Paths, Dependencies
Click on Dependencies, if you are getting compileSdkVersion 28 error the SDK version under Dependencies is pointing to version lower than 28 -> Select 28 or higher
5. Click OK
Now Refactor->Migrate to AndroidX worked for me

In gradle.build (app) add this
compileSdkVersion 28
defaultConfig {
......
minSdkVersion 21
targetSdkVersion 28
......
}
And there are some implementations required to use androidx :-
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
And add these given two lines(below) to gradle.properties:-
android.useAndroidX=true
android.enableJetifier=true

I'm having exact same problem. Been trying to migrate since all the new firebase stuff is forcing it, but the current guides to upgrade are sparse. First I was trying on a backup of my project with a lot of addons and kept getting that error, then I created a brand new flutter project with all the latest (dev channel), followed every step, checked every detail, read every forum, but still getting "You need to have compileSdk set to at least 28 in your module build.gradle to migrate to AndroidX."...
Matched the steps from https://androidxhackathon.blogspot.com/2018/05/refactor-to-android-x.html too and can't get it to refactor right.
Even went to File>ProjectStructure>Project SDK and set to Android API 28 Platform.
Anyone know what we might be missing? Did you have any luck Sam?

Click on Invalidate cache/Restart from file option worked for me

Try replacing the default in dependencies {...} in app/build.gradle with this:
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
The replacement is similar to what is posted in the "Not recommended..." section from this link: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
If you can explain why this works, please add a comment. Thank you!

Go to "Project structure" in the Files menu. Clear out every issue you see there, like
set the android sdk, fix the problems specified

A simple solution.
follow the steps.
Create a new app --> (tick androidX in the window) --> finish
Add some lines in the android --> app --> build.gradle as follow,
update the defaultConfig
minSdkVersion 19
targetSdkVersion 28
multiDexEnabled true
Go to Refractor --> migrateToAndroidx
Do Flutter clean
Restart
Run
hope it works now ...

Related

No documentation in Android Studio 4.0.1 (Linux Mint)

I don't get any description. I've reinstalled Android Studio, deleted whole android profile and cache but still it did't help.
Edit1 - Note: When new API's are released, the documentation is not always released with it. You need to check their update log to determine that.
Install the Sources of the API you are using.
The documentation will show up afterwards.
Steps:
Tools -> SDK Manager
Check "Show Package Details"
Check the required API Source
Wait for indexing to be finished.
When I faced this issue it was because the compileSdkVersion set in app build.gradle was only installed partially according to the SDK manager.
Installing the SDK for the compileSdkVersion fully fixed the documentation issue on Mac OS AS 4.0.1. This is accomplished by simply checking the checkbox.
To illustrate, on this image the documentation would work with compileSdkVersion set to 26 or 29, but not when set to 28 or 30.
Faced the same issue. Clearing cache doesn't seem to the trick.
The thing here is - Sources for Android 30 is not yet available in SDK Manager. So we need to use android 29 at least for development environment to see the documentation. Go through the following steps :
Download Sources for Android 29
Update the following properties in app/build.gradle file :
compileSdkVersion 29
buildToolsVersion "29.0.2"
targetSdkVersion 29

To much errors on Android Studio

I'm starting to program in Java, my goal is to program apps for android.
But Android Studio is giving me such a hard time. I already have some experience with C# and I've programm before with Visual and Unity and never encounter so many errors, theres always something with AS. I'm on Win 7 with Android Studio 3.1.4. Started giving error with adb.exe missing, gradle sync error and then haxm, but i was able to resolve those, but now is giving me error with Render problem failed to find style and Couldn't resolve resource, try the solution of change compileSdkVersion 27 targetSdkVersion 27, but didn't work. I haven't done anything, just start the project and is giving that, I let you with the screenshot, Thanks. This how the error appears
I just resolve it, so leaving this here if anyone encounters these errors. If you just install Android Studio I recommend you to go to file > settings > Android SDK, then tick the box show package details, install Android 8.1 SDK platform 27 and Sources for Android 27. Hit ok, after finish doubleclick on build.gradle module: app, change the values of to these:
compileSdkVersion 27
targetSdkVersion 27
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
The 28 version its giving problems, why? I don't know, but after reading a lot I was able to fix it this way. Especially if you just started with android studio and you installed for the first time.

Android Studio Failed to find target with hash string 'android-26'

I've installed latest Android Studio and
- I've created new project for sdk 25
- I have sdk 25 installed
I have this issues:
first of all, I don't see Tools > Android > AVD Manager. So I have no idea how can I set up additional AVD
second: I get this error in console
Error:Failed to find target with hash string 'android-26' in: C:\Android
Install missing platform(s) and sync project
Why is it complaining about version 26? I have project with api 25 set up?
This problem seem to emerge because AndroidStudio tries to target the last version of SDK it aware of. There few ways to solve it and #HarryFromMarydelDE Jan 7 at 20:18 presented nice solution in form of youtube video. I'll make this answer verbose and more detailed:
One way to deal it is to install sdk-26. You really may not have Android->AVD Manager menu items under Tools menu. You can find SDK Manager icon just under the Android Studio main menu, or open File->Settings (Ctrl+Alt+S) and go to Appearance&Behavior->System Settings->Android SDK
Other way is to find gradle.build file in YourAppName/app folder, find lines: compileSdkVersion 26 and targetSdkVersion 26 in it and change number into SDKs you already have.
But, if you'll change target sdk from 26 to 25, you may encounter more errors. Particularly, if you checked Back Compatibility box when you created your app in wizard. In this case you'll need to change 'com.android.support:appcompat-v7:26.1.0' string to use sdk 25 version of appcompat-v7:25.1.0 in the same file.
After this, you may encounter one more error:
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (25.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
To resolve it, edit app.iml in YourAppName/app folder: change 27.1.1 numbers to 25.1.0 and hopefully, Gradle will finally build your project.

Android Studio - no debuggable applications

I tried to debug a release version of my Android application but Android Studio failed to attach a debugger. (It could not find Android procces of my running application).
Under devices console, there was only a message:
No debuggable applications
You also should have Tools->Android->Enable ADB Integration active.
The solution is to turn on debuggable flag (debuggable true) in application's gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "org.example"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
debuggable true
}
}
}
After Android Studio synced Gradle with project files and reinstalled an application, the debugging start working.
Just click the "Bug" icon and you will be good to go.
I had the same problem and that did the trick.
hope it helps someone.
if intellij or AS you should make sure your Build Variants Setting is debug.
Check if Tools->Android->Enable ADB Integration is enabled.
Also disable and re-enabling it works most of the times.
I want to add one point to above 2 answers :
If Eclipse IDE is running parallel to Android Studio then above answers may not help you. The debuggable application will not refresh event after setting debuggable true in Gradle file.
So, close Eclipse IDE and check in Android Studio. The debuggable application will refresh.
Thank you
Believe it or not,a faulty USB cable can cause this problem to linger even if you follow all the suggestions here.Changing my USB cord did it for me
It happen to me when I wanted to debug my app after I Generated a Sign APK, so I had to change back the Build Variants value from release to debug.
Multiple Options to do this:
1.Tools->Android->Enable ADB Integration
OR
2.Build->Clean Project , the Build-> Rebuild Project. Then "adb kill-server" and "adb start-server"
One of above will work.
You should check also in your AndroidManifest.xml file that there is no option like android:debuggable="false" in your application tag.
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:debuggable="false">
To make it work just remove this option.
Ctrl+shift+A
Type Enable ADB Integration
click on toggle
Done
This is the problem I encountered.The AAR file you import may change the attribute of debuggable, So just remove the debuggable attribute in your Main App Manifest file.
See the picture:
Working solution
1.For testing run as debug if everything is correct process is attached and you can able to debug.Can see in the list
2.If it says application not debuggable then alter gradle
Repeat step 1
4 .If not toggle Tools->Android->Enable ADB Integration and make it enabled.
5.Restart adb server
6.Dis connect and connect device It will list
Believe it or not, if you are on Windows OS, region setting has something to do with this too.
make sure your Regional Format is on English (United States) or actually any setting which makes your Calendar non-unicode (e.g. not On Persian Calendar or Arabic ...)
Apparently someone in Android Studio or ADB Dev team used .toString() with no respect to culture somewhere in their code !
Click the green bug, but make sure the drop down is set to app, if not it will not deploy your app, and just say something about.
Connected to the target VM, address: 'localhost:xxx', transport:
'socket'
Make sure your build variant is set to "debug". And debug has debuggable true on your build.gradle file
I used Mac to run Android Studio. I agree with #Kushal, I did not open Eclipse though.
I shut off Parallels Desktop and other APPs which may use the same Gradle.

Error:Module 'App name': platform 'android-15' not found

I am trying to start a project for google glass in android studio. I have all the SDK platforms required but still android studio keeps on giving me this error. Does anyone have any clue whats going on?
I just selected the update SDK option and then did rebuild. It said daemon started successfully
Sooooo...... remember to make changes in your build.gradle
change compileSdkVersion 15 to compileSdkVersion "Google Inc.:Glass Development Kit Sneak Peek:15"
I changed the compileSdkVersion to a lower one, synced, that failed, changed it back to the previous value, synced and it properly built. Very arbitrary, I know.
I had a similar problem. If you're on a mac than go into Android Studio/preferences/Appearance & Behavior/Android SDK and click on the SDK Tools tab. Update the Android SDK Platform Tools.
After you've updated this in the preference, go to Build/Clean Project. This takes a few seconds. When complete, go to Build/Rebuild Project.
The build should be successful this time.
If this doesn't work then go into file/ invalidate cashes restart
Hope this helps, Good luck.
Change targetSdkVersion and compileSdkVersion to the most current versions.

Resources