Android Studio and android.support.v4.app.Fragment: cannot resolve symbol


해결 방법



I have tried all of the following,

  • Invalidate Caches/Restart
  • Sync project with gradle files
  • Clean project
  • Rebuild project
  • gradlew clean

But, none of them worked for me.

Finally, I solved it by deleting "{ProjectFolder}/.idea/libraries", and then synced with gradle and built again.








출처

https://stackoverflow.com/questions/20386331/android-studio-and-android-support-v4-app-fragment-cannot-resolve-symbol

Posted by MR 손
,

xxhdpi 75dp

xhdpi 50dp


Rect CheckRect = new Rect();

Window window = getWindow();

window.getDecorView().getWindowVisibleDisplayFrame(CheckRect);

int nStatusBarHeight = CheckRect.top;


Posted by MR 손
,




출처 : https://github.com/MostafaGazar/CustomShapeImageView


이클립스 샘플 코드 

ImageCustomizing.zip



Posted by MR 손
,



RecycleViewCardviewExam.zip


필요 라이브러리 프로젝트 3가지 

{ANDROID_SDK}/extras/android/support/v7/appcompat

{ANDROID_SDK}/extras/android/support/v7/recyclerview

{ANDROID_SDK}/extras/android/support/v7/card


MainActivity.java
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.Window;

public class MainActivity extends AppCompatActivity {

	private Context						mContext;

	private RecyclerView				mRecyclerView;

	private RecyclerView.Adapter		mAdapter;
	private RecyclerView.LayoutManager	mLayoutManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// Request window feature action bar
		requestWindowFeature(Window.FEATURE_ACTION_BAR);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// Get the application context
		mContext = getApplicationContext();

		// Change the action bar color
		getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED));

		// Get the widgets reference from XML layout
		mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);

		// Initialize a new String array
		String[] colors = { "Red", "Green", "Blue", "Yellow", "Magenta", "Cyan", "Orange", "Aqua", "Azure", "Beige", "Bisque", "Brown", "Coral", "Crimson"};

		mLayoutManager = new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL);
		mRecyclerView.setLayoutManager(mLayoutManager);

		// Initialize a new instance of RecyclerView Adapter instance
		mAdapter = new ColorAdapter(mContext, colors);

		// Set the adapter for RecyclerView
		mRecyclerView.setAdapter(mAdapter);
	}
}
ColorAdapter.java
import java.util.Random;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


public class ColorAdapter extends RecyclerView.Adapter{
    private String[] mDataSet;
    private Context mContext;
    private Random mRandom = new Random();

    public ColorAdapter(Context context,String[] DataSet){
        mDataSet = DataSet;
        mContext = context;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView mTextView;
        public ViewHolder(View v){
            super(v);
            mTextView = (TextView)v.findViewById(R.id.tv);
        }
    }

    @Override
    public ColorAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        // Create a new View
        View v = LayoutInflater.from(mContext).inflate(R.layout.custom_view,parent,false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position){
        holder.mTextView.setText(mDataSet[position]);
        // Set a random height for TextView
        holder.mTextView.getLayoutParams().height = getRandomIntInRange(250,75);
        // Set a random color for TextView background
        holder.mTextView.setBackgroundColor(getRandomHSVColor());
    }

    @Override
    public int getItemCount(){
        return mDataSet.length;
    }

    // Custom method to get a random number between a range
    protected int getRandomIntInRange(int max, int min){
        return mRandom.nextInt((max-min)+min)+min;
    }

    // Custom method to generate random HSV color
    protected int getRandomHSVColor(){
        // Generate a random hue value between 0 to 360
        int hue = mRandom.nextInt(361);
        // We make the color depth full
        float saturation = 1.0f;
        // We make a full bright color
        float value = 1.0f;
        // We avoid color transparency
        int alpha = 255;
        // Finally, generate the color
        int color = Color.HSVToColor(alpha, new float[]{hue, saturation, value});
        // Return the color
        return color;
    }
}
activity_main.xml



    
    


custom_view.xml


    

AndroidManifest.xml



    
        

    
        
            
                

                
            
        
    





Posted by MR 손
,

AndroidManifest.xml

android:configChanges 에 screenSize를 넣어줘야 onCreate를 다시 타지 않는다.         

 <activity  

          android:name=".MainActivity"

            android:label="@string/app_name" 

            android:configChanges="screenSize|keyboard|orientation"

            > 



Activity




import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	private final String TAG = MainActivity.class.getSimpleName();
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
			
		loadView();		
	}
	
	private void loadView() {
setContentView(R.layout.activity_main);
        Button btn = (Button)findViewById(R.id.rotate_button);
        btn.setOnClickListener(new View.OnClickListener() {
             
            @Override
            public void onClick(View v) {
                if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
                    Log.i(TAG, "SCREEN_ORIENTATION_SENSOR_PORTRAIT");
                } else {
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    Log.i(TAG, "SCREEN_ORIENTATION_SENSOR_LANDSCAPE");
                }
            }
        });
    }
 
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
          loadView();	
        } else {
            loadView();	
        }
    }

}






android:screenOrientation="unspecified"
위와 같은 내용을 적게 되면 핸드폰 설정값에 따라 방향전환이 일어나게 된다.






Posted by MR 손
,

주의사항 : OTA 할 경우 기존에 깔려 있는 데이터는 모두 초기화 됩니다.



1. https://developers.google.com/android/nexus/images?hl=ko

 단말에 맞는 버전 다운로드 



2. 다운 받은 파일 압축 풀기 

hammerhead-mra58k.tgz 형태로 되어 있음




3. 단말을 연결한 후  adb reboot bootloader 명령 실행

  단말이 unlock 모드로 재부팅 됨.


4. 압축푼 파일에서 

  리눅스 및 맥은 ./flash-all.sh 실행

  윈도우는 flash-all.bat 실행


오류 발생시 {ANDROID_SDK}/platform-tools/flashfastboot 경로 문제인 경우일 것이다.

그런경우 flash-base 파일을 열어 


각 명령어 앞에  {ANDROID_SDK}/platform-tools/flash



예) 

/Developer/android-sdk-macosx/platform-tools/fastboot flash bootloader bootloader-hammerhead-hhz12k.img

/Developer/android-sdk-macosx/platform-tools/fastboot reboot-bootloader

sleep 5

/Developer/android-sdk-macosx/platform-tools/fastboot flash radio radio-hammerhead-m8974a-2.0.50.2.27.img

/Developer/android-sdk-macosx/platform-tools/fastboot reboot-bootloader

sleep 5

/Developer/android-sdk-macosx/platform-tools/fastboot -w update image-hammerhead-mra58k.zip



Posted by MR 손
,

안드로이드 프로젝트를 단말에 컴파일 시도 하자 마자 아래와 같은 에러가 발생 되었다.


Error generating final archive: Conversion to Dalvik format failed: [java.io.IOException: The same input jar [/Developer/TstockWorkspace/TestCodeAndroid2/bin/classes] is specified twice.][com.guardsquare.dexguard.eclipse.adt.ae.a(DexGuard7.0.20:220)]


dexguard-project.txt 파일에서 


#-injars      bin/classes

#-injars      bin/resources.ap_


해당 부분을 주석 처리 해주면 된다.


proguard 오류도 동일할 것 같다.

Posted by MR 손
,

apktool 사이트(아래의 사이트에 접속하여 apktool.jar를 다운 받는다)

http://ibotpeaches.github.io/Apktool/



1. 디컴파일 하기

apktool d target.apk

target/ 더로 생성 됨 



2. 빌드하기 

apktool b -o out.apk target/

 - apktool b -o {생성될 apk} {디컴파일 된 폴더}


3. 사이닝 하기 (사이닝 안할경우 Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES] 에러 발생)

jarsigner -keystore mrsohn.keystore -verbose out.apk mrsohn

 - jarsigner -keystore {이름}.keystore -verbose out.apk {alias}



4. 설치하기 

adb install out.apk 




# keystore 생성 하기 

keytool -genkey -keystore mrsohn.keystore -validity 10000 -alias mrsohn

 - keytool -genkey -keystore {이름}.keystore -validity {유효기간} -alias {alias}



# 폰에서 apk 추출 하기 

1. 패키지 목록 조회

adb shell pm list packages -f 

      (예 adb shell pm list packages -f  | grep google 으로 원하는 앱을 찾아낸다

아래와 같이 결과 가 나온다 

package:/system/priv-app/GoogleServicesFramework.apk=com.google.android.gsf

package:/system/app/GoogleContactsSyncAdapter.apk=com.google.android.syncadapters.contacts

package:/data/app/com.skmc.okcashbag.home_google-7.apk=com.skmc.okcashbag.home_google

package:/data/app/com.google.android.apps.books-6.apk=com.google.android.apps.books

package:/system/priv-app/GooglePartnerSetup.apk=com.google.android.partnersetup

package:/system/priv-app/GoogleFeedback.apk=com.google.android.feedback

package:/data/app/com.google.chromeremotedesktop-3.apk=com.google.chromeremotedesktop

package:/data/app/com.google.android.play.games-8.apk=com.google.android.play.games

package:/data/app/com.google.android.gm-6.apk=com.google.android.gm

package:/data/app/com.google.android.youtube-14.apk=com.google.android.youtube



2. apk 가져오기

adb pull /data/app/com.google.android.youtube-14.apk


Posted by MR 손
,