Importing Eclipse Library Project into AndroidStudio - android

I have an Eclipse Project that I like to migrate to AndroidStudio, with the following Structure/Content
1 LibraryProject with most of classes for all my Apps. This Library has 1 Activity ("SharedStarterActivity"), which will be started from all my 3 Apps.
3 Apps using the mentioned LibraryProject. These Apps referencing an Activity of my ProjectLibrary App as the Start Activity in the Apps AndroidManifest.xml.
<activity android:name=".SharedStarterActivity"
android:label="#string/IndividualAppName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In a first look, it does not make sense, but each app has its individual AppProp.class, which is used by the SharedStarterActivity.class and makes each app individual.
Now my question:
How can I migrate this Projects to AndroidStudio ?
I have read the migration guide "from Eclipse to AndroidStudio", but I am stuck now at
"Import Eclipse Projects to Android Studio" -> You should decide how
you will import your existing Eclipse ADT projects depending on their
structure:
Before Trial and Erroring, I wanted to ask you experts, how you would import the projects and will the mechanic still work with referencing an Activity from LibraryProject
in my Android Project (one of the 3 Apps) ?

see there is more types available in Google to migrate eclips to studio but which method I use please follow the step.
1) Open existing project in eclipse remove the library from setting and close eclipse
2) Open AS(Android Studio) import from eclipse option available there, choose the option and open your project in AS.
3) Some Library are already avail in AS. Click on your Main module (Main) press F4 open setting and check your lib available in listing or not.
4) if Avail then add from there else find the latest version of same library and add as module to your Main project.
5) please properly configure your Gradle ( Main Gradle and app Gradle file)
you may also refer below link to migrate in details
https://developer.android.com/studio/intro/migrate.html
or
http://www.developer.com/ws/android/migrating-from-eclipse-to-android-studio.html

Related

Could not identify launch activity: Default Activity not found after upgrading to Android Studio 4.0

I've been having this problem since upgrading to Android Studio 4.0 on macOS. When I try to start my app from Android Studio, I get the following error:
Could not identify launch activity: Default Activity not found
Error while Launching activity
What's a bit unique about my project is that the default activity is defined in the manifest of another library used by my project, not the project itself. This was all working fine before the upgrade, but now it isn't for me. When I open the project containing the dependency, it builds and runs fine. I've already tried the following steps:
clean the project, rebuild
invalidate caches and restart
reinstall Android Studio
delete all generated files and folders (build, gradle, .idea, etc)
You can solve the problem as follows:
Click your Module Selection window,then click Edit Configurations…
Then set Launch Options to Nothing; that's okay:
To dovetail off of Mike N.'s comment, it looks like it is an issue to be resolved in the next point release: https://issuetracker.google.com/issues/158019870
For the details of the quick fix, for me I looked at the Merged Manifest tab, which is at the bottom-left of the AndroidManifest.xml pane. This shows all of the library manifests combined with your activity's.
The dialog said an error occurred where browser:1.0.0 manifest had a minSdk of 15 whereas all the rest of my minSdk are 14. I clicked on:
use a compatible library with a minSdk of at most 14, or increase this
project's minSdk version to at least 15.
Which brought up my minSdk to 15, and the error with the launcher went away, it will now insta-launch on my device. So I would sit tight for AS 4.0.1 but in the meantime, check the Merged Manifest.
For me this was happening in a project in which the main activity was declared in the manifest of an imported module (e.g. not in "app" module).
The solution for me was to add again the activity declaration in the manifest file of my top project:
<activity android:name="com.cristian_slav.elements.MainActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
On my side it was a issue with the manifest. You can detect this type of issue by watching the merged manifest tab. For more details you can watch the link shared by Mike N. in the first comment.
The problem will arise in new projects when one forgets to tick the default activity checkbox during adding anyone of the first or subsequent new activity.
This can be rectified at later stage by going to Run> Edit Configurations > Launch : in which change to specified activity and select the activity you choose to keep as the first page on launch of app.
Try these steps:
Close Android Studio
Go to
C:\Users\my_user_name.AndroidStudio4.0\system\caches
Delete "caches" folder
Relaunch Android Studio
set Launch Options to (Nothing)

How to repair gradle sync and project build in android studio?

I'm new to android studio. I recently made a new project with default MainActivity, then deleted the activity and made a new Activity that i set as default in AndroidManifest.xml by adding
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Since I did that, my whole android studio broke down. I couldn't run any app I previously made or any project I created since then. After hitting run/Shift+F5 it just says
Error running 'app': Default Activity not found
It does this on any project I open/newly create. I am not able to launch with default or any activity, it just says that it isn't declared in manifest file. If it is a newly generated project, it usually won't even launch. I have to sync it with gradle files. After that I am able to sometimes run it, but after every android studio restart it breaks again. Some of my bigger projects were able to start after around 4-5 clean projects and gradle syncs, but broke down again after android studio restart. I have reinstalled android studio and build tools multiple times and I am all out of ideas. Every build or gradle sync is successful without errors, it just can't find the activity to run.
If none of these other troubleshooting options work, such as Invalidate Cache/Restart and Syncing Gradle, it may be the project setup itself.
Most Android Studio projects need at least one module. A module is a way to divvy up the source code based on different devices being targeted (e.g., you may need one for Android TV, one version of your app for Android Wearables, etc.). You can find more info here on that: https://developer.android.com/studio/projects/add-app-module
So make sure you have a module (typically named app or if it's the only one, lower-case version of your app's name maybe). It should have the source code, assets & res folders (drawables and launcher icons and such), the AndroidManifest.xml, and its own build.gradle file separate from the main project's. It doesn't have to have much in there other than where to look for library repositories.
Just ran into this issue when migrating an old project to Android Studio 4.0, this seemed to do the trick.
EDIT: Still working on it, looks like it will run the first time and then it recognizes "No Default Activity" and stops me from running/installing.
EDIT: Figured it out. It is a new issue with AS 4.0 where the merged manifests had a library (from androidx compatability library) that targeted minSdk=15 instead of 14 like I previously had. It appears when I click on that error in the Merged Manifest tab when I have AndroidManifest.xml open (bottom-left of the pane) I am able to run as normal again. See here: https://issuetracker.google.com/issues/158019870

Why do I get two shortcuts of my app, with different behaviour for each?

In android studio (1.0.2), I made a android library on its own project : I've just created a new project and changed the build.gradle, replacing apply plugin 'com.android.application' with 'com.android.library' (github repository). So building it I am ending with a .aar file. Notice that I am also trying to use Kotlin language in order to build it.
Then I imported this aar library file into an existing android project of my own (github repository), adding adjustement to the app build.gradle.
Though it works, at least on my android Emulator (x86 image of Jeally Bean api : 4.2.2), I got a strange behaviour :
In the application list, I got two shortcuts for my new application
But also, while a shortcut just starts with the library main activity, the other starts my owner ChessPositionManager activity, and goes immediatly inside the contained FileExplorer activity.
So, is that behaviour of having two different icons with a little different behaviour is explicable ? Can I avoid it and at the same time keep the fact that I am coding the library and my application separately ? (Indeed, a library module can easily be added to any project, but it is still coupled with this project, as far from what I've understood).
I assume that your library file has a manifest declaration making it show up in your launcher. See if your library manifest has:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
If it does that is why its showing up twice, that intent filter signals to android you want it to show up.
Also, I suggest taking a look at http://developer.android.com/guide/components/intents-filters.html

After adding google-play-service_lib my resourceIds cannot be recognized

I am using ADT 23.0.2.
I just imported the google-play library to my workspace and added the reference to it in my project.
Now nowhere in my project the resource ids can be recognized because there is no R file.
(Anywhere I have R.id.blah I get the error "R cannot be resolved to a variable);
It's just gone. What am I supposed to do?
I exactly followed the steps by developers.google.com. It's nothing complicated but I don't know why this happened.
(I have all layout files in place and no import for android.R are in my class files.)
Before adding the
Tools I use:
Here are screenshots from my app properties:
My manifest
<permission
android:name="com.appname.appname4.MAPS_RECEIVE"
android:protectionLevel="signature">
</permission>
<uses-permission android:name="com.appname.appname4.MAPS_RECEIVE"/>
<activity
android:name="com.appname.appname4.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.appname.appname4.SearchResultListActivity"
android:label="#string/title_activity_search_result_list"
android:parentActivityName="com.appname.appname4.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.appname.appname4.MainActivity" />
</activity>
<activity
android:name="com.appname.appname4.ContactInfoActivity"
android:label="#string/title_activity_property_detail"
android:parentActivityName="com.appname.appname4.SearchResultListActivity"
>
</manifest>
I had similar issues when I first started Android programming. Here are some fixes that worked for me in the past.
1. Fix/Check all xml(layout) files.
Many times a R file not being generated is due to an issue with your layout file or Android Manifest file. Follow this link and work your way down the page checking permissions and the general layout format.
2. Project/Clean.
go to Project->Clean.
Also make sure you have selected the option to build project automatically.(Without this option check marked R file is never generated automatically).
3. Fix Project Properties.
Right click on your project in Package explorer then choose fix project properties.
Repeat Step 1 after this.
4. Builders.
Go to Project->Properties then Builders. Select the appropriate boxes.
Repeat Step 1, and Clean and rebuild project.
5. Appcom7 and Google Play services error.
Sometimes to fix errors associated with installing these two reference libraries. I copy there folders into a generic library folder on my hard(where I keep most of my eclipse reference libraries), after this I delete them from the Package explorer and from the "default" directory where they were installed. I Fix project properties again and clean/rebuild. This should get you back to your non-reference library version of the package. Then I manually add them as Projects to my eclipse IDE and finally follow this to add them as references to my project. Then fix project properties,clean and rebuild.
6. Reference Question.
Finally, referring to this StackOverflow page has helped me countless times. And one way or another fixed my issue.
Good Luck.

Implementing an Android library project

I have an android project that I want to "clone" for a second similar project which only differs by one file: it's sqlite database (assets/mydata.sql).
I've turned the source project (reslib) into a library and added it to my clone project's properties (the source project shows up under "Library Projects" as reslib.jar)
Thing is, I'm not sure how to launch the main activity in the source project. The source project's main activity sets-up a TabHost. How do I launch into the source project's main activity from my clone project? I started pasting code into "cloneActivity.java" to fire up the TabHost but then wondered if there was a better way.
Doing this is pretty straight-forward. In the manifest for your dependent project, you need to specify the source project's activity as the one you want to launch.
Suppose your source project has package name com.example.source, your dependent project has package name com.example.dependent, and the main activity in your source project is MainActivity.java.
Then in AndroidManifest.xml in your dependent project, you would have something like the following:
<application
android:icon="#drawable/logo" >
<activity
android:name="com.example.source.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- possibly lots more activities and other declarations -->
</application>
Important Notes: In the manifests for both your source project and the dependent project, you must make sure to list all activities, permissions, etc. If later on you add an activity to your source project, you'll need to remember to add it to the dependent project's manifest as well.
Also, you'll need to copy anything in the source project's assets directory to the dependent project—and don't forget to keep that in sync as well. (This is true as of June 2012, I've heard that some future version of the Android build tools will likely alleviate this headache.)
And finally, if you use Eclipse to create the projects, it will create a default layout main.xml. Since resources in the dependent project override resources in the source project, make sure this doesn't trip you up.

Categories

Resources