Module not specified after opening project from another computer - android

I keep my projects in my Dropbox folder. I installed Android Studio on my laptop and I tried to open the Project. All java files had a red circle which I managed to fix by marking the Directory as Sources Root. When I try to run the application, the Edit configuration window pops up with a sign at the bottom saying that Module is not specified, in red. There is no module I can select in the appropriate combobox. Syncing project with grandle files has no effect and importing the project instead of opening it makes things even worse. At the Projects side tab, by selecting the Android option, I can only see the Grandle Scripts structure and not the project files. The project files are visible when I select the Project option from the combobox.
The project cannot even open at the original computer anymore. I am new to Android and I have spent a lot of time developing this project. What can I do to reverse the situation?

You have to change some gradle properties.
First you open android studio and create a new project. Then change your old project's all gradle properties according to new project. like bellow--
Go to your build.gradle(Module:app) script and change the gradle version like compile 'com.android.support:appcompat-v7:25.3.1' to your current version.
Go to your build.gradle(Project:your app) script change this line classpath 'com.android.tools.build:gradle:2.3.0' to your current version.
Finally you have to change gradle-wrapper.properties(Gradle Version) distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
to your current version
Now sync your project, I hope it will working fine.

Related

Linking an Android library that is on local machine

I have a set of utils and custom widgets that I want to pull out of my project as an Android library so that I can use them in other projects (and possibly share in the future). I created a new Android Studio project and changed the build.gradle file so that 'com.android.application' was 'com.android.library' and deleted the applicationId. It all compiles fine and I have a .aar file created.
I now want to use this new library as a module in my original project. When I do an Import Project, all the files from the library project are copied into my original project. But I don't want that because if I change the imported library code, it isn't reflected in the library project or vice versa.
I also tried adding this to settings.gradle:
include ':myutils'
project(':myutils').projectDir = new File(settingsDir, '../../../../Development/MyUtils/')
and in the original project app build.gradle:
dependencies {
implementation project(':myutils')
...
But I get this error:
ERROR: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve project :myutils.
Show Details
Affected Modules: app
How can I link the library to my project without importing it? I would prefer not to go through an external maven repo yet. I'm happy to (and would expect to) recompile my library whenever there is a change there and then rebuild my original project.
Thank you in advance.
I think I just had the same problem - I wanted to put the library .aar file somewhere on my local drive and then use it in a new app as a dependency. I didn't want to have to go through a repo or to include it in the libs folder in the new app. Hopefully that is what the OP asked and the following might be of help to others.
Searching on SO (Aug 2021), majority of answers seemed much more involved than what Android Studio offers (tested on version 4.2). That is, an .aar file that lives outside the app project can now be added as an implementation file in the gradle dependencies. So, it doesn't have to go through a repo, and it doesn't have to be included in the libs folder in the project.
The current documentation (Aug 2021) gives a fairly straightforward answer how to do it:
https://developer.android.com/studio/projects/android-library#psd-add-aar-jar-dependency
In short, if you have put your .aar file somewhere on your local drive, this is how to add it as an implementation file in another app project:
In Android Studio, in your new app project, go to: File > Project Structure > Dependencies.
In: Modules > app > Declared Dependencies, click '+' and select 'Jar Dependency'. (Even though you are trying to use an .aar file, you still select 'Jar Dependency').
In the 'Add Jar/Aar Dependency' popup dialog:
in step 1 enter the path to your .aar file on your local drive, and
in step 2 select 'implementation'.
If everything worked out, your build.gradle(Module) should have a line in the dependencies that looks like:
dependencies {
implementation files('../../../MyFolder/MyLibraryFile.aar')
A few notes:
You can actually just add the dependency manually, by typing it into the build.gradle(Module) dependencies, so you don't actually have to go through the Android Studio dialog outlined above.
you can either use a relative path (as the example above), or an absolute path.
the Android Studio dialog is somewhat limited in that you cannot just browse to your file (in point 3, step 1), but you have to actually enter the path manually.
Probably the most important: Whenever you make a change in the library and assemble a new .aar file, then remember to do the following in your app project that uses the .aar file as a dependency: Clean Project, then Sync Project with Gradle Files, and only then run the app, so that the changes in the library could take effect in your app.
I have been using Phgr's above technique for four years. I have three comments -
First, I don't clean the app project each time I change the library - I just do a Sync Project before building and testing the app.
Second, I changed the File-Settings-Keymap-Main Menu-File-Sync to Alt-S for easy of syncing - I hate wasting time using the mouse for selecting the Sync icon.
Third, I have an implementation line in the app's build module file for each app variant such as the following -
debugImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-debug.aar')
releaseImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-release.aar')
All of this is working fine with Android Studio 4.2.2 and sdk version 30.
Hope this helps others with this problem

Android studio: this project is not gradle based project

I have one project which was initially in eclipse, then i managed somehow to convert it to gradle and everything was working fine in Android Studio.
But then i didn't work some time with the project and after few months when i returned to project i am surprised that Android Studio has problems with this project.
When i selected "Android" from top left dropdown in AS, where you should see the project as Android, i saw no files, then i did something and now i see there one empty folder Java.
If i hit button "sync project with gradle files" AS says message as posted in name of question, but it is gradle based project.. there are gradle files etc.
Do you someone know why is this problem? Why it should stop work like this?
Thank you
Make sure you open the project from its root directory. i.e. the directory which contains the top level build.gradle file.
The missing top level gradle file is what causes this error.
For native Flutter Projects:
Note that this error will also appear if you "sync your project with Gradle files " in the root directory. Gradle works only in your android directory (flutter_name/android).
Configure Gradle version
I got this error because i wanted to change some build values like the Gradle version and the Gradle plugin version (and other build values ex. kotlin):
In your current project: File>Open
Select directory: user/StudioProjects/flutter_name/android
Open directory in a new window
After it is opened it will load some packages (see right bottom), which will take some time.
Under File>Project Structure Project you can set the gradle version and under Modules variables of your build
Now you can sync your project with Gradle files or at least read out the error messages, that come with your configuration
After configuration, you might need to restart your project with File>Invalid Caches/Restart....
That worked for me:
copy the file build.gradle
drop the copied file build.gradle in
your app/project folder .
My project stopped showing all of sudden and already had build.gradle file.
I just reopened it via File > Open.

Android Studio Marks syntax as error, but gradle compiles

I have a project in Android Studio which compiles with Gradle.
The general file structure is
MyProject
- MyProjectSource
- Libraries
- ActionBarSherlock
My project is built with Gradle and will compile without issue. However in the lines within my activity where I include a component from ActionBarSherlock, Android Studio marks it as an error.
I have noticed that Android Studio has also generated .iml files. So my question: Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?
Obviously this is not a project blocking problem but it does slow velocity not being able to take advantage of the full set of tools Android Studio has to offer.
Thanks in advance for any help.
These are not errors actually, this a bug in Android studio( 0.4.2 ) for resolving the symbol and fixed for the next release( 0.4.3 ).
To get Rid of these until the release do the following
Clean your project using Build > Clean Project
Close your Android Studio
Take Backup of your project
Delete all .iml files inside your project
Delete content of .idea directory
Open Studio and wait until it completes the sync with gradle
Also verify if you are seeing any error in File > Project Structure . If there is any error saying "Dependency Not Added "click on that and using red bulb on right side Add them to dependency.
UPDATE
Android Studio 0.4.3 is available on Canary Channel Now.
UPDATE: #laochiv, I have found that cleaning manually the folder .idea/libraries and clicking afterward on "Sync Project with Gradle Files" solves the problem. Apparently this Sync does not remove elements, but keep the old ones and add the current ones. Probably a bug to report :)
I am having the same problem. However, I am using ABS directly from Maven.
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
}
Even the ABS Gradle Sample application marks a syntax error, although it compiles.
However, in another computer everything is working perfectly. I can not think of different conditions in each scenario.
"Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?" Yes. Android Studio imports the project configuration but runs its own compiler as you are editing and saving (you can even change it to the Eclipse ECJ compiler). The true authority on the build is Gradle, and AS is still in beta. You can try to run the gradle resync or close and reimport the project. I have had to manipulate AS like this many times, especially after making edits to build.gradle.
Edit: I have found it better to use ActionBarSherlock as a gradle dependency rather than a library directory.
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
You will need to use the SDK manager and install the local maven repository.
But it is possible to eventually get rid of these compile errors, as long as your build.gradle doesn't create any extra sourceSets that AS doesn't understand; try not to deviate too much from the android gradle plugin examples.
Also, I've been running the Canary updates of AS for the latest and greatest.
I don't know how to add a library using MavenCentral. I follow these steps to include a library
Add library in App_Name/App_Name/libs folder.
In App_Name/build.gradle add this
dependencies {
compile ---
compile files('libs/fileName.jar') }
./gradlew clean
Make sure your Android studio is updated.
Go through the link and it worked for me.
1.) Choose File option from menu on left top side of android studio.
2.) Select the option : "Invalidate Cache/ Restart.." It will open an dialog.
3.) Click on the first button with option : "Invalidate and Restart"
4.) It will close the studio and restart it. Start indexing of the project.
It resolved my problem
Go to File -> Invalidate Cache/ Restart -> Invalidate and Restart
Source
https://www.youtube.com/watch?v=FX_gCTpqhwM
I had this problem in Android Studio 4.2, it might be fixed on 4.3
I have noticed that adding some dependencies did not attach the classes.jar to the dependency, so Gradle recognises everything but the IDE doesn't. To fix it:
Open Module Settings of your project
Select the dependency that has the error
Click Add (+) for that dependency (bottom of the pop up)
Navigate to your-project/build/exploded-bundles/your-dependency/classes.jar
The IDE should recognise the files now
Hope it helps
I had this today and gradle update/sync didn't solve. But updating to latest version of Android Studio 2.2 update 5 fixed (was on 2.1).
Here i'm talking about android studio version v3.1.2 where this same issue happened.In later android studio version(above 3.0.1) this issue again rises. So, I solved this by going through few things and here is how
Close android studio first
Navigate to your Project Folder
Delete .gradle and .idea folder (.gradle and .idea is hidden files. so make sure you tick Show Hidden Files in your File Explorer option to see these files
Open your project in android studio now
This Time another issue (unsupported module) will arise, but don't worry. I got you
Goto File in android studio and hit Sync Project with Gradle Files
Tada..! you're done now!
Simplest Solution
Comment/Remove the dependency which is showing syntax error & Sync Project.
Uncomment/Add again & Sync Project.
Yeah! error gone...
Before
After

Unable to start Android Studio after installation

I am trying to start Android Studio for the first time but getting error mentioned below
Could someone please let me know how to solve this error?
You need to set your JAVA_HOME path, which will allow Android Studio to run. Have you done that?
Here is how to do that:
Right click your Computer icon, and click Properties
Windows 8 Users: Then click Advanced System settings to your left.
Now, go to the advanced tab, click Environment variables, under
system variables, click New, and add a JAVA_HOME variable, it should
look like this (relative to your jdk version, if its the latest
it should be identical).
If you already have that covered I found a solution here that can help you:
Go to your AndroidStudio directory where you installed your studio Like D:\User\AndroidStudio
In AndroidStudio go to \AndroidStudio\plugins\gradle\lib and copy gradle.jar
Paste this gradle.jar file to \AndroidStudio\lib directory.
Download gradle directly from Gradle
Copy the contents of gradle-1.7-bin.zip - After extracting zip file - (bin, media, init.d, lib folders) to \AndroidStudio\plugins\gradle
Restart AndroidStudio
http://developer.android.com/sdk/installing/studio.html#Troubleshooting
Scroll to the bottom.
Troubleshooting
Figure 1. Error dialog when opening an existing project.
Error: Gradle project refresh failed
Android Studio 0.2.0 has updated the Gradle plug-in to 0.5.0, which is not backwards compatible. When opening a project that uses an older version of the plug-in, Studio will display the error shown in figure 1 in the upper right corner of the IDE. To resolve the error, you must change the version of the Android Gradle plug-in to 0.5.0.
Click the link in the error dialog Search in build.gradle files. If the dialog is no longer visible, click Event Log in the bottom-right corner of the IDE, then click Search in build.gradle files.
Double-click the line under the build.gradle usage. For example: classpath 'com.android.tools.build:gradle:0.4. This opens the project build.gradle file.
Edit the classpath to change the gradle version to 0.5.+. For example:
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
For me, I searched for task manager, opened it, went to more options, ended all background android studio tasks, and it worked.\
This happens because sometimes android studio does not fully close properly

What is Android Dependencies? Remove it from Build Path, ClassNotFoundException occurs

I'm working on a team project. I included a .jar file in Build Path and committed to SVN. When I updated code in my working directory, a new folder appears in Eclipse called "Android Dependencies". If I let it be there, my program runs; If I remove it, my program reports a ClassNotFoundException.
Now how to fix this ClassNotFoundException?
For the people whose heart dropped when they read the comment that deleting the Android Dependencies virtual folder will destroy your project, there is an easy fix.
Right click on the destroyed project
Select "Android Tools > Fix Project Properties" in the dropdown
I hosed my project dependencies when trying to set up my git repo, and this is fixed it.
Android Dependencies is a virtual folder where Eclipse shows what JAR files the project depends on. It's not a physical folder; you won't find it on your hard disk. And the folder is not checked in into Subversion.
Do not delete that folder. You will destroy your project.
To fix it, just revert to an older Subversion revision and check it in again.
I've had a similar problem after setting up a git repo with my project.
The problem was that the appcompat import lost its folder reference.
If the 'Fix Project Properties' mentioned doesn't work for you try this:
Go to Project > Properties
Go to the 'Android' tab
Under 'Libraries', if there's a red 'X' next to the appcompat folder, remove
it then hit 'add' and add it in again. The reference should show a
green tick now.
Save and clean the project if needs be
If you also have marked project build target below API level 16 in the Android project properties, the error is going to come because prior to this level, there was no Android dependencies.

Categories

Resources