Import eclipse project to latest Android Studio API

Asked

Viewed 646 times

8

I imported the project from an eclipse app for Android Studio. The import went smoothly and Gradle was created. However, I realize that the visual components like Edittext, Progressbar, Appbar, Button are with a lagged look, the version 3.0 android. I upgraded my minSdk to 15 and targetSdk to 23 and upgraded Radle, but the visual components are still in the old Apis.

I also realize that every time I create a new Activity, I have the following pattern:

import android.app.Activity;
import android.os.Bundle;

public class TesteActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_teste);
    }
}

As activitys inherit only from Activity, and not of Appcompatactivity, as seen below in any project created in Android Studio:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

By altering the inheritance of TesteActivity of Activity for AppCompatActivity, Android does not recognize the class. Remembering that this problem occurs only within the eclipse imported project.

Is there any way to import this old project, to work with the most modern components/features of Android Studio?

3 answers

6

Try putting

compile 'com.android.support:appcompat-v7:23.3.0'

Under "dependencies" in the build.Gradle file

  • Even putting this in the dependencies, it continues with the message of Cannot solves Symbol 'Appcompatactivity' when inheriting the class. When running Gradle to update, the error appears: * What Went Wrong: A problem occurred evaluating root project 'spinsuite-brerp'. > Could not find method Compile() for Arguments [com.android.support:appcompat-v7:23.3.0] on org.gradle.api.internal.artifacts.dsl.dependencies.Defaultdependencyhandler_decorated@3ad836c1.

  • See which version you use, it’s usually the same as buildTools. 'com.android.support:appcompat-v7:(Your version)'

1

Manually change the code to inherit from Appcompatactivity.

About widgets (Edittext, Button, etc.), check your Styles.xml file. See which theme is set. Try to use a theme you inherit from Material.Theme

  • When I change the class code to inherit from Appcompatactivity it is not recognized, it is as if the Appcompatactivity class does not exist.

  • On the subject, I already tried to change and the application crash when I do this, unfortunately I didn’t save the log from errors. The worst thing is that even when I went back to old Heme, the app kept crashing when it opened, needing to clone the repository again.

1


After much research, I was able to find where the problem was.

The class AppCompatActivity is only available from sdk tools 22, and my project was using 21. So, I updated the sdk tools of my build.Radle (Module:app) and restarted Android Studio, being as follows.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "org.spinsuite.base"
        minSdkVersion 14
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
}

After that, I went to the Build/Rebuild project menu. By doing this, just import import android.support.v7.app.AppCompatActivity; in the desired class and extend extends AppCompatActivity. I’m having some crash problems during the execution of the application, but in the project everything is ok. I believe this error is subject to another topic.

Related question:
https://stackoverflow.com/questions/18084808/if-i-use-new-v7-appcompat-library-do-i-still-need-v4-support-library-fo
https://stackoverflow.com/questions/30803405/cannot-resolve-symbol-appcompatactivity-support-v7-libraries-arent-recognized
https://stackoverflow.com/questions/34947794/cant-resolve-appcompatactivity

Browser other questions tagged

You are not signed in. Login or sign up in order to post.