Archive | Fedora RSS feed for this section

How to setup ADT (Android Development Tools) on 64bit Fedora 17 ?

9 Jan

Quick Intro

Yesterday I was excited to receive a task to install ADT for Eclipse and Android SDK on my machine , I thought it would be a “piece of cake”, so with a high level of excitement I have started….

As I use  my laptop with Fedora 17 (64bit) for all my developments, I have decided that I will put my Android Development Tools in it as well.

Installation…

As my first step I went to the http://developer.android.com/sdk/index.html and thankfully there is ADT bundle for Linux 64-bit, which consists of custom version of Eclipse Juno, equipped with everything one needs for Android development and  Android SDK that includes such tools as Android debugger and Emulator.

After downloading Android SDK I have run Eclipse, and surprisingly, instead of default Eclipse intro, ADT-equipped Eclipse has fancy intro:

adt-intro

ISSUE 1: Android Project Replaced with Android Application Project

After Eclipse has fully loaded, I have decided to create an Android Project. My instructions said that I need to go to File -> New – >”Android Project”. Unfortunately, the version that I have installed does not have option “Android Project”. Closest option to “Android Project” was “Android Application Project”. Here is the screenshot:

Android Development_tools_create_project

After trying to find “Android Project” for at least half an hour, I have discovered that other people have the same issue:

http://stackoverflow.com/questions/11329753/no-android-project-option-in-eclipse
http://stackoverflow.com/questions/11604641/difference-between-android-application-project-and-android-project

Solution:

So my decision was to use “Android Applciation Project”, I have just unchecked option to select launch icon.

I have set Project name, Package name and Activity. Everything seemed to be fine and my project was populated with whole bunch of android related files.

ISSUE 2: R Cannot be resolved to a variable   and adb cannot be found

After project files were generated I have faced my next problem. In my src file I had 2 errors regarding “R” which cannot be resolved. After doing a research again I have found out that even more people have the same issue:

http://stackoverflow.com/questions/7906606/after-installing-android-adt-14-r-cannot-be-resolved
http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error
http://stackoverflow.com/questions/8266100/r-cannot-be-resolved-in-eclipse-android-project
http://stackoverflow.com/questions/7824730/r-cannot-be-resolved-to-a-variable
…………

Most of the advices were to clean and rebuild the project which did not gave me any results. One of the advice was to install ia32-lib, however this library is available for other “distros”, but not Fedora.
After 2 hours of trying different stuff, which did not work, I have found out the cause of the problem.

Reason of the error:

The reason why R cannot be resolved is because R should point to the R.java file, which is auto generated and is located in the gen folder. In our case R.java was not generated, thus Eclipse was not able to resolve it.

Together with “R cannot be resolved” error, Eclipse Error Log gave me one more error which looked like this:

Unexpected exception 'Cannot run program 
"/home/aspektor/adt-bundle-linux-64/sdk/platform-tools/adb": error=2 
No such file or directory' while attempting to get adb version from

It looked to me that these problems are connected.

Solution:

After couple of hours of trying tons of different things, I have realized that the reason of the problem is that Android SDK is initially intended for 32 bits. As I have 64bit Linux I need to install additional 32bit packages to make it work.

Thankfully I have found wonderful guide, that helped me in solving most of my issues:

http://fedoraproject.org/wiki/HOWTO_Setup_Android_Development

I have run this command to install 32bit packages:

# yum install glibc.i686 glibc-devel.i686 libstdc++.i686 
zlib-devel.i686 ncurses-devel.i686 libX11-devel.i686 
libXrender.i686 libXrandr.i686

I have also set up PATH in ~/.bash_profile so adb and other tools can be found:

export ANDROID_SDK_HOME=/home/aspektor/adt-bundle-linux-64/sdk
PATH=$PATH:$HOME/adt-bundle-linux-64/sdk:$HOME/adt-bundle-linux-64/tools
export PATH
# For SDK version r_08 and higher, also add this for adb:
PATH=$PATH:$HOME/adt-bundle-linux64/sdk/platform-tools
export PATH

Finally, I have restarted Eclipse, cleaned and rebuild my project and 5 hours later..... tired but satisfied I have created ADV (emulator) and run my ADT project.

Thankfully it worked:

eclipse-works

After-thoughts…

I think it would be reasonable for Android website to ADVICE (put it in bold and somewhere where everyone could see? ) people who have 64-bit Linux need additional 32 bit libraries. It would save folks like me a lot of time. Not saying that these packages should be per-requisite before downloading bundle :)

If you have any other comments, go ahead, I would love to hear them!

Regards,

Anatoly

How to reset root password in Linux (RHEL,FEDORA) ? What to do if you forgot root password ?

18 Sep

Today I want to give you some very useful tips on what to do if you have forgotten your root password.
ATTENTION: This trick will only work if didn’t  setup GRUB password yet.    (if you did – sucks to be you :) )

Use Case:

You want to install something, change permissions on a file  or  do any other action that actually requires root password , which you don’t remember. I would start to panic, If i where you, but wait, there is some small hack you can do, to get back on track.

In this post I will show you how you can become a root without knowing you root password and reset it. I will also give you tips how to protect yourself from this vulnerability.

Let’s start.

1. Boot in Single User Mode

 a. Reboot your computer
 b. Wait until menu say’s to press any key to the Boot/GRUB menu, press any key

   At this point you should see menu similar to this:

grub-menu-image

c. Point to the OS you forgot your  password from and press “e

 
d.  Go to “kernel” line and add word “single” to the end of kernel string.

e. Press “b” to boot with new option for kernel

   Note: If you did something wrong, you could see “black screen of death” but don’t worry, everything you edit in boot menu is temporary, just reboot and you are good to go again.

c. If you did everything correctly you should see command line interface, where you are logged in as “root”.

How cool is that ?

2. Set SELinux to Permissive

a. If you try to change password right away, in RHEL or Fedora you won’t be able to do it because SELinux by default is enforcing.

  Good thing is that we can easily change SELinux enforcing mode. First lets find out the state of SELinux and if it is Enforcing, lets change it to Permissive. Type this in your command line:


$ getenforce

Enforcing

$ setenforce 0

Permissive

4. Change Root Password


$passwd

new password: ******

You will see that all tokens are updated.  Type ‘reboot’, and after you reboot, you will have your NEW root password. (write it down!) :)

But what if someone else would want to change my password in the same way ?

This is very legit question, and it was my first thought when I found out this easy way to change root password. How to protect yourself ? The answer is to put password on Boot menu.

How to lock GRUB/Boot menu ? ( I will show it on GRUB, however GRUB2 works similarly)

Here are a couple of simple steps how to set password on your GRUB:

 1. Open Terminal and login as root:


$ su -

Enter your root password.

2. Now type:

$ grub-md5-crypt

3. Enter password you want your grub (this can be different from your root password)  and click enter you will get md5 encoded string.

Let’s say your  md5 string is:


$1$sdlfksdlfksdlf/

4. Now use your text editor to go to grub.conf file, I use VI:

vi  /boot/grub/grub.conf

after “hidemenu” line enter:

password –md5 < paste here your encrypted md5 string>

(in my case it would be: password –md5 $1$sdlfksdlfksdlf/ )

5. Save the file.

6. To check if it works, try logging to Single User Mode, you will set instead of “e” to edit kernels string, you will need to enter password first.

That’s it for today!

Regards,

Anatoly

SWT migration To GTK+3.x : 6 SWT – Cairo Patches (Eclipse Bugzilla)

15 Jun

I am glad that you guys showed big interest to the project I am currently working on.  I have received couple of emails from blog readers asking to share patches they I have pushed upstream.

First of all, I want to mention that patches are still in “pending” stage, but I hope that they will be reviewed very soon.

For those who want to go ahead, and try   them before they are officially reviewed by Eclipse community, here is the link to 6 SWT patches I have pushed to upstream so far:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=380287
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382384
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382391
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382402
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382407
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382626

If you find anything that you think is wrong, please let me know.

Any feedback is appreciated!

Regards,

Anatoly

 

Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3″

SWT migration to GTK+ 3.x: Use Cairo Instead GDK : First Patch – Tracker Widget

7 Jun

I am continuing series of posts about   SWT migration to GTK+ 3.x . Today, I will  write about patch for SWT Tracker Widget, that omits some of GTK+ 3.x deprecated methods.

When I started working on patch for Tracker, it was very important for me understand what Tracker Widget is intended to do. I found very good implementation of  SWT Tracker widget   here 

Actual code is:


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tracker;

public class Tracker_test {

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.open();
shell.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event e) {
Tracker tracker = new Tracker(shell, SWT.NONE);
tracker.setRectangles(new Rectangle[] { new Rectangle(e.x, e.y, 100, 100), });
tracker.open();
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

When you run this code, you see small rectangle. It appears when you  right-mouse click and disappears when you  release right-mouse click. It looks like this:

From this example, we can see that Tracker is intended to track mouse movements and mouse clicks. It works great, the only problem is that some code in Tracker Widget is outdated, and it won’t built with GTK+ 3.x. I am talking about code in drawRectangles() method inside Tracker.java.

Let’s look at this code:


void drawRectangles (Rectangle [] rects) {
int   window = OS.gdk_get_default_root_window();
if (parent != null) {
window = OS.GTK_WIDGET_WINDOW (parent.paintHandle());
}
if (window == 0) return;
//TODO: Use Cairo
int gc = OS.gdk_gc_new (window);
if (gc == 0) return;
int /*long*/ colormap = OS.gdk_colormap_get_system ();
GdkColor color = new GdkColor ();
OS.gdk_color_white (colormap, color);
OS.gdk_gc_set_foreground (gc, color);
OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS);
OS.gdk_gc_set_function (gc, OS.GDK_XOR);
for (int i=0; i
Rectangle rect = rects [i];
int x = rect.x;
if (parent != null && (parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - rect.width - x;
OS.gdk_draw_rectangle (window, gc, 0, x, rect.y, rect.width, rect.height);
}
OS.g_object_unref (gc);
}

If we take a look at  GDK documentation , we will find out that gdk_gc_newgdk_color_white gdk_gc_set_foreground, gdk_gc_set_subwindow, gdk_gc_set_function and even  gdk_draw_rectangle are all deprecated since GTK version 2.22 and should not be used in newly written code. And as a hint, there is ‘ // TODO: Use Cairo’.

So I here is some of the changes I made to this code:

1. I replaced gdk_gc_new  with  gdk_cairo_create

2. OS.gdk_gc_set_function (gc, OS.GDK_XOR)  was replaced with equivalent function  Cairo.cairo_set_operator(cairo,Cairo.CAIRO_OPERATOR_DIFFERENCE)  (this function is responsible for rectangle to disappear on mouse release)

3. gdk_draw_rectangle was replaced with cairo_rectangle, as cairo saves everything to buffer first, you need to release changes. In my case I used cairo_stroke. ( it fills just contour of rectangle)

4. gdk_color_white was replaced with  cairo_set_source_rgb(cairo, 1, 1, 1);

5. I also had to add line width,  and antialising (without antialising  line width didn’t work)

So my code looks like this:

if(OS.USE_CAIRO){
int /*long*/ cairo = OS.gdk_cairo_create(window);
if (cairo == 0) error (SWT.ERROR_NO_HANDLES);

Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
Cairo.cairo_set_line_width(cairo, 1);
Cairo.cairo_set_operator(cairo,Cairo.CAIRO_OPERATOR_DIFFERENCE);
Cairo.cairo_set_antialias(cairo, Cairo.CAIRO_ANTIALIAS_NONE);

for (int i=0; i<rects.length; i++) {
Rectangle rect = rects [i];
Cairo.cairo_rectangle (cairo, rect.x, rect.y, rect.width, rect.height);
Cairo.cairo_stroke(cairo);
}
Cairo.cairo_destroy(cairo);
return;
}

After run with Cairo, I have the same output as GTK version does.

I have posted bug report with my patch here:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=380287  ( As for June 7, patch is not reviewed yet, as Eclipse reviewers are extra-busy with new version of Eclipse coming out very soon)
I have coded couple of other patches, and I will definitely do some posts on them after this first patch is reviewed.

Regards,

Anatoly

Update:

Unfortunately there is one case where current patch does not work properly, as it supposed to. This case is when you pass “display” to the Tracker constructor. In GDK version it is supposed to use GDK_INCLUDE_INFERIORS that puts rectangle on top of all other windows, however Cairo does not have this luxury, and all my attempts to put in on top is clipped by child windows.

I keep on working on it, and I will keep you updated!

 

Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3″

What is Standard Widget Toolkit for Eclipse (SWT) ?

15 May

Here I am at my new workplace. Next 8 months I will be working in Eclipse team, on migration of SWT  from GTK2 to GTK3.

If these words does not tell you much, don’t worry, I am pretty much in the same situation, but what I am going to do in the next couple of days is to explore this issue as much as I can, and  write down my findings here.

Let’s start with SWT.  My first stop in finding info about SWT was here: http://www.eclipsepluginsite.com/swt.html

After reading  introductory chapter,  I have  found out that SWT stands for   Standard Widget Toolkit.  As I have understood from the reading, SWT is a collection of tools, intended for creating stand alone java applications or eclipse plugins  with basic UI components (such as buttons, trees etc). What is  special about SWT, is that it uses native OS components, so when you build application with SWT it feels like this application is intended for the particular OS.

I decided to build a simple application using one of the examples provided in the reading.

Simple SWT Application

/*
 *  Name: BlogButton.java
 *  Description:  SWT  button on click changes text and background color
 *
 *  Author: Anatoly Spektor
 *  Date: May 14,2012
 * */

import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.*;

public class BlogButton {

public static void main(String[] args) {
 // creating new object of Display myDisplay
 //in SWT Display manages connection between app and OS
 final Display myDisplay = new Display();
 // creating instance of shell - which is actual window
 Shell myShell = new Shell(myDisplay);

// setting window title
 myShell.setText("Window Title");
 //setting size
 myShell.setSize(400,400);
 // setting layout
 myShell.setLayout(new FillLayout());
 // creating button object in myShell
 // passing PUSH behaviour
 final Button button = new Button(myShell, SWT.PUSH);
 // passing button label
 button.setText("Show Blog URL");

// adding event listener to button
 button.addSelectionListener(new SelectionAdapter() {
 public void widgetSelected(SelectionEvent event) {
 //on selected change button label
 button.setText("myprogrammingblog.com");
 // set text color to red
 button.setForeground(myDisplay.getSystemColor(SWT.COLOR_RED));

}
 });

// open - pushes shell on the top of drawing order and makes it visible
 myShell.open();

// checking if shell is Disposed or not
 while (!myShell.isDisposed()) {
 // check if there is work to do for this shell and if not
 // put it in sleep mode so no CPU is consumed
 if (!myDisplay.readAndDispatch()) myDisplay.sleep();
 }
 // disposing an object
 myDisplay.dispose();
 }
 }

Output:

Before Click:
SWT button before click

After Click:

SWT button after click snapshot

 

Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3″

Follow

Get every new post delivered to your Inbox.

Join 272 other followers

%d bloggers like this: