NAIROBI, Kenya — Gay rights in Africa suffered another setback when President Yoweri Museveni of Uganda told members of his party on Friday that he would sign a bill imposing harsh sentences for homosexual acts, including life imprisonment in some cases.

The measure would criminalize “the promotion or recognition” of homosexual relations. After a first conviction, offenders face a 14-year prison sentence. Subsequent convictions of “aggravated homosexuality” could bring a penalty of life in prison.

The announcement of the president’s intentions came during a conference of Mr. Museveni’s party, the National Resistance Movement, according to a government spokesman. “The NRM caucus has welcomed the development as a measure to protect Ugandans from social deviants,” said the spokesman, Ofwono Opondo, in a post on Twitter on Friday.

According to Amnesty International, homosexuality is illegal in 38 of 54 African countries.

Homosexual acts can be punished by death sentences in Mauritania, southern Somalia, Sudan and northern Nigeria, where justice is carried out according to a version of Shariah law. After President Goodluck Jonathan of Nigeria signed a law criminalizing homosexuality throughout the country last month, arrests of gay people have multiplied amid demands for a crackdown.