[英]Android app works on emulator but will not install on my phone
I am teaching myself to program android apps, i wrote a simple tip calculator as a starter project. 我在教自己编写android应用程序,我写了一个简单的小费计算器作为入门项目。 The program runs fine on the emulator, but when i export an apk file it wont install on my phone.
该程序可以在模拟器上正常运行,但是当我导出apk文件时,它不会安装在手机上。 i transferred the file with out adb because adb wont detect the device.
我用adb传输了文件,因为adb无法检测到设备。 i am on ubuntu 12.04, i have the vendor code in udev rules, the device is Huawei Ascend (M860) how can i find a log of what went wrong.
我在ubuntu 12.04上,我在udev规则中有供应商代码,设备是Huawei Ascend(M860)我怎么能找到发生问题的日志。 or an idea of what i did wrong.
或对我做错了的想法。
this is the main java file: 这是主要的Java文件:
package com.groundscore.gstipcalc;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends Activity {
// Constants used when saving and restoring
private static final String TOTAL_BILL = "TOTAL_BILL";
private static final String CURRENT_TIP = "CURRENT_TIP";
private static final String BILL_WITHOUT_TIP = "BILL_WITHOUT_TIP";
private double billBeforeTip; // Users bill before tip
private double tipAmount; // Tip amount
private double finalBill; // Bill plus Tip
EditText billBeforeTipET;
EditText tipAmountET;
EditText finalBillET;
SeekBar tipSeekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);// Inflate the GUI
// Check if app just started, or if it is being restored
if(savedInstanceState == null){
billBeforeTip = 0.0;
tipAmount = .15;
finalBill = 0.0;
} else {
// App is being restored
billBeforeTip = savedInstanceState.getDouble(BILL_WITHOUT_TIP);
tipAmount = savedInstanceState.getDouble(CURRENT_TIP);
finalBill = savedInstanceState.getDouble(TOTAL_BILL);
}
// Initialize the EditTexts
billBeforeTipET = (EditText) findViewById(R.id.billEditText);
tipAmountET = (EditText) findViewById(R.id.tipEditText);
finalBillET = (EditText) findViewById(R.id.finalEditText);
tipSeekBar = (SeekBar) findViewById(R.id.changeTipSeekBar);
tipSeekBar.setOnSeekBarChangeListener(tipSeekBarChangeListener);
billBeforeTipET.addTextChangedListener(billBeforeTipListener);
}
private OnSeekBarChangeListener tipSeekBarChangeListener = new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
tipAmount = (tipSeekBar.getProgress()) * .01;
tipAmountET.setText(String.format("%.02f", tipAmount));
updateTipAndFinalBill();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
};
private TextWatcher billBeforeTipListener = new TextWatcher(){
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
try{
billBeforeTip = Double.parseDouble(s.toString());
}catch(NumberFormatException e){
billBeforeTip = 0.0;
}
updateTipAndFinalBill();
}
};
private void updateTipAndFinalBill() {
double tipAmount = Double.parseDouble(tipAmountET.getText().toString());
double finalBill = billBeforeTip + (billBeforeTip * tipAmount);
finalBillET.setText(String.format("%.02f", finalBill));
}
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
outState.putDouble(TOTAL_BILL, finalBill);
outState.putDouble(CURRENT_TIP, tipAmount);
outState.putDouble(BILL_WITHOUT_TIP, billBeforeTip);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
this is the layout: 这是布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".GsTipCalc" >
<TextView
android:id="@+id/billTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="15dp"
android:text="@string/bill_text_view" >
</TextView>
<EditText
android:id="@+id/billEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:hint="@string/bill_edit_text"
android:inputType="numberDecimal"
android:layout_alignParentLeft="true"
android:layout_marginLeft="11dp"
android:layout_alignParentTop="true"
android:layout_marginTop="38dp" />
<EditText
android:id="@+id/finalEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/changeTipSeekBar"
android:layout_alignLeft="@+id/billTextView"
android:ems="5"
android:hint="@string/bill_edit_text"
android:inputType="numberDecimal" />
<TextView
android:id="@+id/finalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/finalEditText"
android:layout_alignLeft="@+id/finalEditText"
android:text="@string/final_text_view" />
<TextView
android:id="@+id/tipTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/tipEditText"
android:layout_alignLeft="@+id/tipEditText"
android:text="@string/tip_text_view" />
<SeekBar
android:id="@+id/changeTipSeekBar"
android:layout_width="89dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/tipEditText"
android:layout_marginRight="37dp"
android:layout_marginTop="84dp"
android:progress="15" />
<EditText
android:id="@+id/tipEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/billEditText"
android:layout_alignBottom="@+id/billEditText"
android:layout_alignLeft="@+id/changeTipSeekBar"
android:ems="3"
android:inputType="numberDecimal"
android:text="@string/tip_edit_text" />
<TextView
android:id="@+id/SlideTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/finalEditText"
android:layout_alignLeft="@+id/changeTipSeekBar"
android:text="@string/change_tip_text_view" />
</RelativeLayout>
This is the Logcat read out from the install attempt: 这是从安装尝试中读取的Logcat:
I/ActivityManager( 7588): Starting: Intent { dat=file:///mnt/sdcard/GsTipCalc.apk cmp=com.android.packageinstaller/.InstallAppProgress (has extras) } from pid 14921
I/ActivityManager( 7588): Displayed com.android.packageinstaller/.InstallAppProgress: +347ms
D/dalvikvm(14940): GC_EXPLICIT freed 4K, 50% free 2696K/5379K, external 0K/0K, paused 275ms
W/ActivityManager( 7588): No content provider found for:
D/VoldCmdListener( 207): asec list
I/PackageHelper(14940): Size of container 2 MB 234323 bytes
D/VoldCmdListener( 207): asec create smdl2tmp1 2 fat {} 10022
W/logwrapper(14978): Unable to background process (No such file or directory)
I//system/bin/newfs_msdos( 207): /system/bin/newfs_msdos: warning, /dev/block/dm-2 is not a character device
I//system/bin/newfs_msdos( 207): /system/bin/newfs_msdos: Skipping mount checks
I//system/bin/newfs_msdos( 207): Bogus heads from kernel - setting sane value
I//system/bin/newfs_msdos( 207): Bogus sectors from kernel - setting sane value
I//system/bin/newfs_msdos( 207): /dev/block/dm-2: 4176 sectors in 522 FAT32 clusters (4096 bytes/cluster)
I//system/bin/newfs_msdos( 207): bps=512 spc=8 res=32 nft=2 sec=4221 mid=0xf0 spt=63 hds=64 hid=0 bspf=5 rdcl=2 infs=1 bkbs=2
I/Vold ( 207): Filesystem formatted OK
D/VoldCmdListener( 207): asec path smdl2tmp1
I/PackageHelper(14940): Created secure container smdl2tmp1 at /mnt/asec/smdl2tmp1
I/DefContainer(14940): Created container for smdl2tmp1 at path : /mnt/asec/smdl2tmp1
I/DefContainer(14940): Copied /mnt/sdcard/GsTipCalc.apk to /mnt/asec/smdl2tmp1/pkg.apk
D/VoldCmdListener( 207): asec finalize smdl2tmp1
I/DefContainer(14940): Finalized container smdl2tmp1
I/DefContainer(14940): Unmounting smdl2tmp1 at path /mnt/asec/smdl2tmp1
D/dalvikvm(14940): GC_EXPLICIT freed 17K, 50% free 2695K/5379K, external 0K/0K, paused 71ms
D/dalvikvm( 7588): GC_EXPLICIT freed 227K, 38% free 6615K/10631K, external 609K/1800K, paused 169ms
D/VoldCmdListener( 207): asec unmount smdl2tmp1 force
W/ActivityManager( 7588): No content provider found for:
D/VoldCmdListener( 207): asec mount smdl2tmp1 {} 1000
D/VoldCmdListener( 207): asec path smdl2tmp1
D/PackageParser( 7588): Scanning package: /mnt/asec/smdl2tmp1/pkg.apk
E/PackageParser( 7588): Package com.groundscore.gstipcalc has no certificates at entry res/layout/activity_main.xml; ignoring!
I/PackageHelper( 7588): Forcibly destroying container smdl2tmp1
D/dalvikvm( 7588): GC_EXPLICIT freed 135K, 39% free 6530K/10631K, external 609K/1800K, paused 169ms
D/VoldCmdListener( 207): asec destroy smdl2tmp1 force
D/dalvikvm( 7588): GC_EXPLICIT freed 14K, 39% free 6528K/10631K, external 609K/1800K, paused 245ms
I think you may have used "Project Right Click -> Android Tools -> Export Unsigned Application Package" and inadvertently created an unsigned APK. 我认为您可能使用了“项目右键单击-> Android工具->导出未签名的应用程序包”,并且无意间创建了未签名的APK。 Unsigned APKs will not run on neither the emulator nor actual device.
未签名的APK将不会在模拟器或实际设备上运行。 When you run the app from Eclipse to an emulator, the APK is signed with a debug certificate, so in this way the APK is still signed.
当您从Eclipse到模拟器运行应用程序时,APK会用调试证书签名,因此,APK仍会签名。
The fastest way to get an APK to be transfer to your device would be go to dir /bin, there should be an APK there which is refreshed everything you've changed something AND has run the changes on the emulator. 将APK传输到设备的最快方法是转到dir / bin,那里应该有一个APK,可以刷新您所做的所有更改并在模拟器上运行更改。
Your phone appears on the devices list?? 您的手机出现在设备列表中?
For you know, go to your adb installation and run the adb tool 如您所知,请转到adb安装并运行adb工具
you_path\\adt-bundle-windows-x86_64\\sdk\\platform-tools you_path \\ ADT-束窗口-x86_64的\\ SDK \\平台工具
adb devices
This should list your devices connected to your tool. 这应该列出您连接到工具的设备。
Make sure the emulator is down. 确保模拟器关闭。
May be , There will be a problem in your minSdkVersion
, targetSdkVersion
! 可能是,您的
minSdkVersion
, targetSdkVersion
会有问题!
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
minSdkVersion="8" : for android 2.3 minSdkVersion =“ 8”:对于Android 2.3
targetSdkVersion = "17" for android 4.1 对于Android 4.1,targetSdkVersion =“ 17”
your phone is Lower SDK , and your .apk file is created with Higher SDK . 您的手机是Lower SDK,而.apk文件是使用Higher SDK创建的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.