A much simpler way to fix all importing errors
Tinribs507 opened this issue · 21 comments
So I did have quite a long and complicated fix which required you to copy and paste alot of code and other things.
After finishing this course I came up with similar issues for the next course. So I thought, rather than trying to figure everything out again, what would happen if I start a blank project and just change the file names to match exactly to the Miwok app.
After doing this, copy and paste over the code for each .java file and XML files. As long as you create a new project with EXACTLY the same name as the project you're working on, this is all you will need to do.
So this is what you need to do:
Step 1:
Start a new project named exactly Miwok or whatever project you are trying to import.
Step 2:
Copy the Java files from the Miwok app into your app in exactly the same folder.
Step 3:
Copy the XML files from the Miwok app into your app in exactly the same folder.
Step 4:
Copy over the files from the Resource folder into your app in exactly the same folder.
This is by far the simplest way of getting the app to work. Make sure you're using the requirements that the course dictates. Some courses need specific libraries downloaded, but they will inform you at the beggining.
I hope this helps!
Edit:
If you have problems with the AppCompatActivity in the MainActivity.java file, hover over the AppCompatActivity text and click on "Import class".
Then delete the unused import at the top of the page and you're good to go!
how to import other files(main activity,xml and other files).could you please tell?
Theres a feature in android studio that will auto import for you.
So if you were to try and use a class in one java file that isn't already imported it will import automatically.
This website will help you:
http://tutorialspots.com/enable-auto-import-in-android-studio-3851.html
tried but nothing worked . have no clue what to do now.
What do you mean nothing works? Can you elaborate?
I forgot to mention and will update the fix:
Click on the little box with the blue arrow in the top right hand corner of Android Studio.
On the screen that pops up, click on "Show Package Details" in the bottom right of the screen.
Make sure you have these boxes ticked:
Under Android 10.0(Q):
Android SDK platform 29
Sources for Android 29
Google APIs intel x86 Atom System Image
Under Android 6.0 (MarshMallow)
Android SDK Platform 23
Sources for Android 23
Then click on SDK Tools at the top of the page and again, click on "Show Package Details".
Make sure these boxes are ticked:
Under Android SDK Build-Tools 30-rc2:
29.0.3
27.0.3
23.0.2
Then get back to me and let me know if that worked.
- Estimated download size: 1.1 GB
- Estimated disk space to be additionally occupied on SDK partition after installation: 4.6 GB
will let you know when it is done.
Ok cool, if it doesn't work start a new project with the instructions and code i provided in the solution.
Failing that, you basically build the app from scratch anyway.
The code that isn't provided to you in the tutorial you can copy off of the downloaded project files.
So my advice to you is, if it still doesn't work (Although it should) Just start the course with a brand new project and go from there. I've just finished it and you really don't use much of that code anyway.
You haven't copy and pasted the code I supplied into the build.gradle file
I have just finished the first course and because of how amazingly informative and easy understanding it is I couldn't wait to start on the second course.
Unfortunately, because this course is quite old, the project was riddled with errors for me and it took a good 2-3 hours of searching, trial and error and alot of cursing before I fixed it.Here's how I fixed the errors I had.
(Bear in mind, if you have edited any of the files it may not work. You may want to re-download the Miwok app and start fresh for this to work)Click on the little box with the blue arrow in the top right hand corner of Android Studio.
On the screen that pops up, click on "Show Package Details" in the bottom right of the screen.
Make sure you have these boxes ticked:Under Android 10.0(Q):
Android SDK platform 29
Sources for Android 29
Google APIs intel x86 Atom System ImageUnder Android 6.0 (MarshMallow)
Android SDK Platform 23
Sources for Android 23Then click on SDK Tools at the top of the page and again, click on "Show Package Details".
Make sure these boxes are ticked:Under Android SDK Build-Tools 30-rc2:
29.0.3
27.0.3
23.0.2The next thing I did was create a new project in order to obtain the code needed for the build.gradle Module:app file.
I copied all the text from that and pasted it into the Miwok app build.gradle Module:app.
(For begginners in this, there's 2 build.gradle files. One is for the project (This has alot less text than the Module:app one) and the other is the Module:app. Make sure you're picking the right file to edit.Here is the code you need to copy and paste into the Miwok built.gradle Module:app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"defaultConfig { applicationId "com.example.android.miwok" minSdkVersion 15 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}Once you have done this, you need to find the build.gradle Project: app. Copy and paste this code into that file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'// NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }
}
allprojects {
repositories {
jcenter()
}
}task clean(type: Delete) {
delete rootProject.buildDir
}Once you have done this, sync the files. It will ask you to update Gradle to the latest version but you should click on "Don't remind me for this project", and voila... Job done!
Now I'm going to start on this course, wish me luck!
after updating sdk versions,tools.i also imported miwok app using git.
this error comes up.what to do?
could you please help?
You haven't copy and pasted the code I supplied into the build.gradle file
i pasted the code in my first attempt. and followed exactly as you posted.
Check out the new fix @mesnuuu and @sachin-dubey.
The next course after this has similar issues, so I used this on both the Miwok app and the next course app and they both work.
Let me know if this works please :)
I did what you told before.
just copied above mentioned gradle files.
but new error comes up.
TRIED ADDING.
maven {
url 'https://maven.google.com/'
name 'Google'
}
BUT THIS ALSO DIDN'T WORKED.
Tinribs507 ,could you please help? and thanks a lot for helping us.
I completed the Android basics course a week ago and I had issues how to update all my imported projects.
My conclusion was the same like yours @Tinribs507.
Whenever I failed to implement for example the androidx library, then I created a new project and copied the files what I needed.
Step 2:
Copy the Java files from the Miwok app into your app in exactly the same folder.
Little suggestion guys who copy and paste all the java files.
When you create a new project then you basically use androidx instead of android.support.v7.
please delete this line of code from your MainActivity.java file (and any other java files where you find this):
import android.support.v7.app.AppCompatActivity;
and use this import:
import androidx.appcompat.app.AppCompatActivity;
Refactor the existing app by migrating it to AndroidX
This link helped me
@sachin-dubey I have the same problem as yours. Have you got it fixed? If yes plz help
@sakshamg19 .yep i fixed it. please share screenshot of the issues.
@sakshamg19 were you able to fix it?
So I did have quite a long and complicated fix which required you to copy and paste alot of code and other things.
After finishing this course I came up with similar issues for the next course. So I thought, rather than trying to figure everything out again, what would happen if I start a blank project and just change the file names to match exactly to the Miwok app.
After doing this, copy and paste over the code for each .java file and XML files. As long as you create a new project with EXACTLY the same name as the project you're working on, this is all you will need to do.
So this is what you need to do:
Step 1:
Start a new project named exactly Miwok or whatever project you are trying to import.
Step 2:
Copy the Java files from the Miwok app into your app in exactly the same folder.
Step 3:
Copy the XML files from the Miwok app into your app in exactly the same folder.
Step 4:
Copy over the files from the Resource folder into your app in exactly the same folder.
This is by far the simplest way of getting the app to work. Make sure you're using the requirements that the course dictates. Some courses need specific libraries downloaded, but they will inform you at the beggining.
I hope this helps!
Thank you so much!